URAL 1936 Roshambo 题解

时间:2023-03-09 16:37:06
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 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 ( ≤ n ≤ ). Output
Output the expected amount of years that will be taken off from winner. Absolute or relative error should be no more than −. Sample Input
input output 1.5

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

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

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

但,

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

e[i]表示从i个人的状态开始,决出最后一个人所需步数的期望。

e[1]=0,e[i]=(e[i-1]*(1/3)^i*3+1)+(e[i-2]*3*(1/3)^i+1)+...+(e[1]*...)+e[i]*(1-psum),

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

//我发现那个kn=1.0然后慢慢减,得的答案特别逗,要kn=0,然后慢慢加,才不逗,这是什么原理
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
using namespace std; long double f[];
long double jc[];
long double cf[]; int main()
{
int i,j;
jc[]=1.0;
for(i=;i<=;i++)
jc[i]=jc[i-]*i;
cf[]=1.0;
for(i=;i<=;i++)
cf[i]=cf[i-]*3.0;
f[]=;
f[]=1.5;
for(i=;i<=;i++)
{
f[i]=;
long double kn=0.0;
for(j=;j<i;j++)
{
long double k=1.0/jc[j]/jc[i-j]/cf[i-]*jc[i];
kn+=k;
f[i]+=k*(1.0+f[j]);
}
f[i]+=1.0-kn;
f[i]/=kn;
//cout<<i<<". "<<f[i]<<" kn="<<kn<<endl;
}
int n;
while(scanf("%d",&n)!=EOF)
printf("%lf\n",(double)f[n]);
return ;
}