码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1936 Roshambo 题解

时间:2014-06-08 22:28:26      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

http://acm.timus.ru/problem.aspx?space=1&num=1936

bubuko.com,布布扣
F - Roshambo
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice URAL 1936

Description
Bootstrap: Wondering how its played?
Will: Its a game of deception. But your bet includes all the dice, not just your own. What are they wagering?
Bootstrap: Oh, the only thing we have. Years of service.
Will: So any crew member can be challenged?
Bootstrap: Aye. Anyone.
Will: I challenge Davy Jones.
All that the pirates have on the Flying Dutchman is the years of service that are left for them. Every crewman wants to shorten it. That is why gambling is very popular on the ship, the winner have a chance to shorten his years of service significantly.
Pirates often gather to play “Roshambo”, also known as “rock-scissors-paper”. The game consists of several sets. In the beginning of each set players stand in a circle, count to three and show one of three gestures simultaneously, conventionally called as rock, scissors and paper. If everyone shows the same gesture or if each of the three gestures is shown, then nobody leave the game and they play another set. If among the shown gestures there are only two different then only players that chose the victorious gesture play the next set. Scissors beats rock, rock beats paper and paper beats scissors. The game continues until the only one player is left, and that pirate is called the winner. The winner’s time of service is shortened on the number of years that equals the number of the sets played, while the losers get extra years.
Bootstrap Bill decided to try his fortune. You should help him determine the expected value of prize in case of his victory. Pirates don’t know any complicated strategies for this game. So you can suppose that pirates show every gesture equiprobably.

Input
The only line contains integer n that is the number of sailors that are going to play, including Bill (2 ≤ n ≤ 100).

Output
Output the expected amount of years that will be taken off from winner. Absolute or relative error should be no more than 10?6.

Sample Input
input    output

2

    

1.5
题目,格式混乱,清点上面链接查看原题

题意就是求N个人剪刀石头布直到剩下最后一个人所用的盘数的期望值。

我以前做过类似的题,叫“闪电劈人概率计算器”,输入三国杀游戏中,从自己开始逆时针的座位依次为己方还是敌方,闪电判定一次劈中的概率,求现在自己放闪电,劈中的人是敌方的概率。这是一道让人算完之后能悟到不要乱放闪电的题,这题已经失传了,因为出这题的服务器再也不开了。那是一个神奇的小机房,想当年我们在那里努力练习补刀……不,各种算法。

但,

这种题其实就是手算出公式然后输进去嘛!

这题有点不一样,数字实在太大了,它说精确到6位小数,其实后面的数据放松了。只精确到几万,后面全是0,都能过,简直逗。

bubuko.com,布布扣
 1 2
 2 3
 3 4
 4 5
 5 6
 6 7
 7 8
 8 9
 9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 
45 //我发现那个kn=1.0然后慢慢减,得的答案特别逗,要kn=0,然后慢慢加,才不逗,这是什么原理
46 #include<cstdio>
47 #include<iostream>
48 #include<cstring>
49 #include<vector>
50 #include<stack>
51 #include<queue>
52 #include<cmath>
53 using namespace std;
54 
55 long double f[111];
56 long double jc[111];
57 long double cf[111];
58 
59 int main()
60 {
61     int i,j;
62     jc[1]=1.0;
63     for(i=2;i<=100;i++)
64         jc[i]=jc[i-1]*i;
65     cf[0]=1.0;
66     for(i=1;i<=100;i++)
67         cf[i]=cf[i-1]*3.0;
68     f[1]=0;
69     f[2]=1.5;
70     for(i=3;i<=100;i++)
71     {
72         f[i]=0;
73         long double kn=0.0;
74         for(j=1;j<i;j++)
75         {
76             long double k=1.0/jc[j]/jc[i-j]/cf[i-1]*jc[i];
77             kn+=k;
78             f[i]+=k*(1.0+f[j]);
79         }
80         f[i]+=1.0-kn;
81         f[i]/=kn;
82         //cout<<i<<". "<<f[i]<<"    kn="<<kn<<endl;
83     }
84     int n;
85     while(scanf("%d",&n)!=EOF)
86         printf("%lf\n",(double)f[n]);
87     return 0;
88 }
View Code

 

URAL 1936 Roshambo 题解,布布扣,bubuko.com

URAL 1936 Roshambo 题解

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/yuiffy/p/3775521.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!