尤拉計劃605題:結對投幣遊戲

lt發表於2017-05-28

Consider an n -player game played in consecutive pairs: Round 1 takes place between players 1 and 2 , round 2 takes place between players 2 and 3 , and so on and so forth, all the way up to round n , which takes place between players n and 1 . Then round n+1 takes place between players 1 and 2 as the entire cycle starts again. In other words, during round r , player ((r−1) mod n)+1 faces off against player (r mod n)+1 .

During each round, a fair coin is tossed to decide which of the two players wins that round. If any given player wins both rounds r and r+1 , then that player wins the entire game. Let Pn(k) be the probability that player k wins in an n -player game, in the form of a reduced fraction. For example, P3(1)=12/49 and P6(2)=368/1323 . Let Mn(k) be the product of the reduced numerator and denominator of Pn( (k) . For example, M3(1)=588 and M6(2)=486864 . Find the last 8 digits of M108+7(104 +7) .

用sql來模擬一下,對於3人遊戲,選手1至少要在第4輪才可能獲勝,下次要到第7輪,有可能無限迴圈下去。下面的資料,r是輪次,w表示每輪獲勝者編號,s是序列,z是最終獲勝者編號。

var n number
exec :n:=3
with a as(select level x from dual connect by level<=2)
,t(r,w,s,z) as(select 1,level l,level,cast(null as number) from dual connect by level<=2
union all
select r+1,mod(x+(r-1),:n)+1,s*10+mod(x+(r-1),:n)+1 ,decode(mod(x+(r-1),:n)+1,w,w,null)from t,a 
where z is null and r<10 )
select * from t;

         R          W          S          Z
---------- ---------- ---------- ----------
         1          1          1
         1          2          2
         2          2         12
         2          3         13
         2          2         22          2
         2          3         23
         3          3        123
         3          1        121
         3          3        133          3
         3          1        131
         3          3        233          3
         3          1        231
         4          1       1231
         4          2       1232
         4          1       1211          1
         4          2       1212
         4          1       1311          1
         4          2       1312
         4          1       2311          1
         4          2       2312

相關文章