概率DP HDU 4586 play the dice
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4586
解题思路:
只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加。
对于运气好,摇中了可以再来一次,该轮就能获得m/n*(sum/n)
运气好,又再来一次,该轮能获得(m/n)^2*(sum/n)
无穷无尽的摇下去,一共能获得sum/n*(1+p + p^2+`````+p^k + ````),其中p = m/n
将式子化简,就能得到E = sum/(n-m)。所以当sum = 0时为0,n=m时为inf。其余就为sum/(n-m)。
贴代码:
#include<cstdio>
int main()
{
// freopen("in.c","r",stdin);
int n,m,a;
while(~scanf("%d",&n))
{
int sum =;
for(int i=; i<n; ++i)
{
scanf("%d",&a);
sum += a;
}
scanf("%d",&m);
for(int i=; i<m; ++i)
scanf("%d",&a);
if(sum == ) printf("0.00\n");
else if(n == m )printf("inf\n");
else printf("%.2f\n",(double)sum/(n-m));
}
return ;
}
概率DP HDU 4586 play the dice的更多相关文章
- 概率DP hdu 3366 .
题意:一个人被困在一个城堡里,面前有n条路,他自己有m百万元,选择每一条路都有p概率通过,q概率遇到士兵,1-p-q概率道路不通:遇到士兵的话需要上交1百万,如果不够钱,则被杀死,问的是最优情况下多少 ...
- hdu 4586 Play the Dice(概率dp)
Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equ ...
- hdu 4586 Play the Dice 概率推导题
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- hdu 4586 Play the Dice (概率+等比数列)
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...
- HDU 4586 Play the Dice (数学,概率,等比公式,极限)
题意:给你一个n面的骰子每个面有一个值,然后其中有不同值代表你能获得的钱,然后有m个特殊的面,当你骰到这一面的时候可以获得一个新的机会 问你能得到钱的期望. 析: 骰第一次 sum/n 骰第二 ...
- 概率dp HDU 4405
Aeroplane chess Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 概率dp HDU 3853
H - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ci ...
- [概率dp] hdu 5378 Leader in Tree Land
题意: 给你一颗以1位根节点的树.我们定义对于每一个子树,节点权值最大的权值记为这个子树的权值,为你将1~n放到这个树里 满足最大权值仅仅有k个的组合数是多少. 思路: 我们能够知道以每一个节点为子树 ...
- HDU 4586 Play the Dice(数学期望)
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
随机推荐
- iframe 通信问题
iframe作用: 1:页面部分刷新(iframe也是一个window,html是完整的不是部分html片段) 2:跨域 3:父子window通信 iframe1.window.xx=xx;paren ...
- unity自义定摇杆
写在前面,摇杆控制人物的移动,摄像机跟随人物移动,且滑动屏幕可以控制摄像机观察人物的角度. 需要考虑的问题 1.摇杆滑动角度的计算. 2.摇杆控制效果程度的计算(即:摇杆距离中心位置越远人物的移动速度 ...
- spoj Prime Generator
题意:判断ll-rr范围内的质数. 一个个用miller-rabin算法判断 //#pragma comment(linker,"/STACK:1024000000,1024000000&q ...
- codeforces 555b//Case of Fugitive// Codeforces Round #310(Div. 1)
题意:有n-1个缝隙,在上面搭桥,每个缝隙有个ll,rr值,ll<=长度<=rr的才能搭上去.求一种搭桥组合. 经典问题,应列入acm必背300题中.属于那种不可能自己想得出来的题.将二元 ...
- android--------Retrofit+RxJava的使用
Retrofit是Square公司开发的一款针对Android网络请求的一个当前很流行的网络请求库. http://square.github.io/retrofit/ https://github. ...
- 快速读入fread
struct FastIO { static const int S = 1e7; int wpos; char wbuf[S]; FastIO() : wpos(0) {} inline int x ...
- python-day41--数据库---数据类型
一.存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 二.mysql 数据类型 1.数字:(宽度指的是显示宽度,与存储无关) 不用指定宽度, ...
- 使用XML Publisher导出PDF报表
生成XML数据源有两种方式. 一种是使用存储过程,返回一个clob作为xml数据源. 另一种是直接使用VO中的数据生成xml数据源. 方法一参考: Oracle XML Publisher技巧集锦 O ...
- HashMap知识点、问题
转载:https://blog.csdn.net/qq_27007251/article/details/71403647 https://www.cnblogs.com/kxdblog/p/4323 ...
- Py打包exe报错
Py打包exe报错 下载地址 https://github.com/pyinstaller/pyinstaller 用管理员执行 pip install https:/ ...