URAL 1936 Roshambo 题解

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

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

Description
Bootstrap: Wondering how it‘s played?
Will: It‘s 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,都能过,简直逗。

 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 }

时间: 2024-10-26 23:26:08

URAL 1936 Roshambo 题解的相关文章

POJ 1936 All in All 题解

寻找一个串是否是另外一个字符串的子串序列. 可以想象主串是一连发子弹,而需要查找的子串是一队敌人,然后主串的字符是目标,把主串的所有子弹打完,是否能把子串的所有敌人消灭掉. 很简单的题目. #include <stdio.h> const int MAX_N = 100001; char seq[MAX_N], subSeq[MAX_N]; int main() { while (~scanf("%s %s", subSeq, seq)) { char *s = seq,

URAL 1932 The Secret of Identifier 题解

http://acm.timus.ru/problem.aspx?space=1&num=1932 B - The Secret of Identifier Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1932 Description Davy Jones: You've been captain of the Black Pearl for

ural 1960 Palindromes and Super Abilities 题解

题意:给一个串s,按顺序一个个加入到序列里面.输出每次加入之后序列中的本质不同的回文串个数. 回文自动机模板题- -extend函数里面,如果那个if进去了,就代表多了一个本质不同的回文串. 1 #include<cstdio> 2 #include<cstring> 3 const int MAXN=100000+5; 4 const int SIGMA_SIZE=26; 5 struct Node{ 6 int num,len; 7 Node* go[SIGMA_SIZE],*

ural 1057 Amount of degrees 题解

题目大意:统计区间[x,y]中在b进制下含k个1的数字个数. 数位dp. 具体见2009刘聪论文<浅谈数位类统计问题>... 1 #include<cstdio> 2 const int MAXN=32; 3 int f[MAXN][MAXN]; 4 void init() 5 { 6 f[0][0]=1; 7 for(int i=1;i<MAXN;++i) 8 { 9 f[i][0]=f[i-1][0]; 10 for(int j=1;j<=i;++j) 11 f[i

URAL 2011. Long Statement题解

传送门 题意:有N个为1或2或3的数,问用这N个数的排列方式是不是有6中以上. 思路:降智题,显然六个数以上无论这六个数是怎么组成,只要有两种数字就一定能组成6种,5种及以下我就懒得找规律了,直接全排列统计. AC程序 using namespace std; const int maxn=105; int a[maxn],n,ans; set<int> se; map<string,bool> ma; int main() { cin>>n; for(int i=0;

poj 2352 &amp; Ural 1028 数星星 题解

一道水题,由于x坐标递增y坐标也递增于是前缀和统计即可,用树状数组实现. #include<bits/stdc++.h> using namespace std; const int maxn=15010; const int maxx=32010; inline long long read(){ long long x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar();

训练赛题解

突然想到好久以前做完这份题目没写题解.蛮来写写吧.很多细节已经忘记了.. 第一题 很简单的字符串比对是否b包含a.不包含就报NO,包含就YES..坑爹的第一次!!.把strlen放在了for循环里面..就超时了..超时了.. 注意:for里面的条件每次也会重新计算. A - All in All Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice P

URAL 1244 Gentlement DP +记录路径 好题

1244. Gentlemen Time limit: 0.5 secondMemory limit: 64 MB Let's remember one old joke: Once a gentleman said to another gentleman:— What if we play cards?— You know, I haven't played cards for ten years…— And I haven't played for fifteen years…So, li

URAL 1297 后缀数组:求最长回文子串

思路:这题下午搞了然后一直WA,后面就看了Discuss,里面有个数组:ABCDEFDCBA,这个我输出ABCD,所以错了. 然后才知道自己写的后缀数组对这个回文子串有bug,然后就不知道怎么改了. 然后看题解,里面都是用RMQ先预处理任意两个后缀的最长公共前缀,因为不太知道这个,所以又看了一下午,嘛嘛-- 然后理解RMQ和后缀一起用的时候才发现其实这里不用RMQ也可以,只要特殊处理一下上面这个没过的例子就行了,哈哈--机智-- 不过那个国家集训队论文里面正解是用RMQ做的,自己还得会和RMQ一