LIHKG 概率題: 飛機座位 (升級挑戰版)
P.Plate 2024-10-6 00:58:52 係咪裝個ide /compiler
放入去就run到

Ads

約束をしよう 2024-10-6 01:26:04 你用咩機
Mac/linux的話直接去terminal compile就得
cc file_name.c -o file_name
./file_name

Windows嘅話裝C compiler好麻煩
:^(

一係你等我聽日寫個python version比你,十分鐘搞掂
P.Plate 2024-10-6 01:28:40 Windows
純粹有興趣學下 simulation
:^(
倪淑珸 2024-10-6 01:56:20 n = 1, P(n) = 1
n = 2, P(n) = 1/2 = 1 - 1/2
n = 3, P(n) = 7/18 = 1 - 1/2 - 1/9
n = 4, P(n) seems to be 47/144 = 1 - 1/2 - 1/9 - 1/16
個 pattern 好似係 1/2 - 3^(-2) - 4(^-2)
鳩估條算式係 1/2 - 3^(-2) - 4^(-2) - 5^(-2) - ... - (n-1)^(-2) - n^(-2)
:^(
P.Plate 2024-10-6 02:13:47 你計左n=4?
睇下你點計

有冇人simulate下n=4 n=5嘅情況
倪淑珸 2024-10-6 03:46:23 Sorry 頭先用筆算計錯咗
:^(

用 excel 窮舉法計多次,P(n = 4) = 1/3
:^(

:^(
旋風管家一拳超人 2024-10-6 10:34:58 why
n = 3, P(n) = 1 - 1/2 - 1/9
約束をしよう 2024-10-6 10:52:56 我simulation都計到1/3
Enter the number of passengers: 4
Enter the number of runs: 5000000
Success rate: 33.340280%

Enter the number of passengers: 5
Enter the number of runs: 50000000
Success rate: 29.462626%

Enter the number of passengers: 6
Enter the number of runs: 50000000
Success rate: 26.529514%
約束をしよう 2024-10-6 11:17:19 Simulation係幾好玩
:^(

Python ver(慢C十倍)
:^(
倪淑珸 2024-10-6 12:23:37 報告 P(n=5) 用 excel 窮舉計到 29.506173% (239/810)
:^(

巴打個 simulation 應該幾準
:^(
倪淑珸 2024-10-6 12:29:08 我計錯數,其實無關係的,請巴打忘記佢
:^(

Ads

約束をしよう 2024-10-6 12:43:22 Nice
:^(

不過我呢個最多3個sig fig
倪淑珸 2024-10-7 02:38:32 受好奇心驅動 plot 咗個機率分佈
:^(

原來越多乘客,2號乘客越傾向坐返自己個位
:^(


同埋最後登機o既乘客,坐返自己個位o既機率
同坐喺原本 assign 俾1號客個位o既機率理論上係一樣
:^(
:^(
P.Plate 2024-10-7 04:20:21 點樣plot到咁exact
:^(

唔係用simulation?
旋風管家一拳超人 2024-10-7 09:42:27 想問問個表係咩意思
what is the meaning of a cell that is in row I and column j
倪淑珸 2024-10-7 09:56:50 用 power query 窮舉
再用 excel formula 計同 plot
:^(


整完後我更好奇係咪可以用 matrix generate
即係好似計 Markov chain 嗰啲咁
:^(
倪淑珸 2024-10-7 10:31:22 Row P1, P2, P3...
代表第幾位上機嘅乘客

Column S1, S2, S3...
代表原本 assign 咗俾邊位乘客嘅座位
個數字對應返乘客上機嘅次序
同實際印喺登機證上面嘅座位編號無關
例如當班機總共有 6 位乘客
S6 代表最後一名登機乘客 P6 原本嘅座位

啲 cell 入面個百分比就係某位乘客最終坐喺某個位嘅機率
旋風管家一拳超人 2024-10-7 10:35:38 我可能都唔係太明

如果乘客a佔用乘客b個位 咁其他所有人坐乘客b嘅位應該嘅機會係零
倪淑珸 2024-10-7 10:38:26 你講緊嘅係某一個 scenario
呢個 plot 係綜合所有 scenario 之後得出嘅機率場
旋風管家一拳超人 2024-10-7 10:39:25 Oh, so you mean that for row I and column J It means the I passenger on board will sit on the purchase seat of passenger J.
倪淑珸 2024-10-7 10:40:00 Yes

Ads

旋風管家一拳超人 2024-10-7 10:43:30 原來越多乘客,2號乘客越傾向坐返自己個位
:^(


This is very normal, because The possibility of the second passenger on board seating his own seat solely depends on the first passenger.
倪淑珸 2024-10-7 10:45:25 Plot 咗個圖清晰啲
:^(
約束をしよう 2024-10-7 14:23:22
:^(
倪淑珸 2024-10-7 21:41:56 巴打見笑喇,我覺得你寫o既 simulation programme 更有用
:^(