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 ;
}
URAL 1936 Roshambo 题解的更多相关文章
- URAL 1936 Roshambo(求期望)
Description Bootstrap: Wondering how it's played? Will: It's a game of deception. But your bet inclu ...
- Ural 1029 Ministry 题解
目录 Ural 1029 Ministry 题解 题意 题解 程序 Ural 1029 Ministry 题解 题意 给定一个\(n\times m(1\le n \le10,1\le m \le50 ...
- Ural 1298 Knight 题解
目录 Ural 1298 Knight 题解 题意 题解 程序 Ural 1298 Knight 题解 题意 给定一个\(n\times n(1\le n\le8)\)的国际象棋棋盘和一个骑士(基本上 ...
- Ural 1238 Folding 题解
目录 Ural 1238 Folding 题解 题意 题解 程序 Ural 1238 Folding 题解 题意 定义折叠.展开为: 单个大写英文字母是一个折叠的串,把它展开后是它本身. 如果\(S\ ...
- URAL题解三
URAL题解三 URAL 1045 题目描述:有\(n\)个机场,\(n-1\)条航线,任意两个机场有且只有一种方案联通.现有两个恐怖分子从\(m\)号机场出发,第一个人在机场安装炸弹,乘坐飞机,引爆 ...
- URAL题解二
URAL题解二 URAL 1082 题目描述:输出程序的输入数据,使得程序输出"Beutiful Vasilisa" solution 一开始只看程序的核心部分,发现是求快排的比较 ...
- URAL题解一
URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...
- Ural 1248 Sequence Sum 题解
目录 Ural 1248 Sequence Sum 题解 题意 题解 程序 Ural 1248 Sequence Sum 题解 题意 给定\(n\)个用科学计数法表示的实数\((10^{-100}\s ...
- Ural 1201 Which Day Is It? 题解
目录 Ural 1201 Which Day Is It? 题解 题意 输入 输出 题解 程序 Ural 1201 Which Day Is It? 题解 题意 打印一个月历. 输入 输入日\((1\ ...
随机推荐
- Linux(10.5-10.11)学习笔记
3.2程序编码 unix> gcc -01 -o p p1.c p2.c -o用于指定输出(out)文件名. -01,-02 告诉编译器使用第一级或第二级优化 3.2.1机器级代码 机器级编程两 ...
- 20145222黄亚奇《Java程序设计》第10周学习总结
20145222 <Java程序设计>第10周学习总结 学习总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接 ...
- 7.HBase In Action 第一章-HBase简介(1.2.1 典型的网络搜索问题:Bigtable的起原)
Search is the act of locating information you care about: for example, searching for pages in a text ...
- Spring的BeanPostProcesser接口介绍
前言 废话不多说,直接进入主题. 同学们有想过这么一种情况吗:Spring容器提供给我们的一些接口实现类并不能满足我们的要求,但是我们又不想重新写一个类,只想在原来类上修改一些属性? 举个例子,Spr ...
- ROM存储1/4周期正弦信号构造DDS
上周的时候,老师让编写一个简单的dds程序,本文说明了整个过程中我遇到问题以及一些个人的思考.初次接触FPGA,如有问题请多多指教~ 1.几个疑问,解决和没有解决的. 为何采用ROM而不是直接采用DD ...
- Scala学习笔记(七):Application特质
Scala提供了特质scala.Application 在单例对象名后面写上“extends Application”,把想要执行的代码直接放在单例对象的花括号之间 import ChecksumAc ...
- CSS 外边距合并
外边距合并指的是,当两个垂直外边距相遇时,它们将形成一个外边距. 合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者. 外边距合并 外边距合并(叠加)是一个相当简单的概念.但是,在实践中对网 ...
- [BZOJ 1797][AHOI2009]最小割(最小割关键边的判断)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1797 分析: 在残余网络中看: 对于第1问: 1.首先这个边必须是满流 2.其次这个边 ...
- AngularJS开发指南13:AngularJS的过滤器详解
AngularJS过滤器是用来格式化输出数据的.除了格式化数据,过滤器还能修改DOM.这使得过滤器通常用来做些如“适时的给输出加入CSS样式”等工作. 比如,你可能有些数据在输出之前需要根据进行本地化 ...
- struts2理解
(1) Struts2(一)---struts2的环境搭建及实例 (2) struts2(二)---ModelDriven模型驱动 (3) Struts2属性驱动与模型驱动 (4)