HDU 4586 Play the Dice(数学期望)
Play the Dice
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3648    Accepted Submission(s):
1181
Special Judge
1,2,...,n and have the equal possibility to show up when one rolls a dice. Each
side has an integer ai on it. Now here is a game that you can roll this dice
once, if the i-th side is up, you will get ai yuan. What's more, some sids of
this dice are colored with a special different color. If you turn this side up,
you will get once more chance to roll the dice. When you roll the dice for the
second time, you still have the opportunity to win money and rolling chance. Now
you need to calculate the expectations of money that we get after playing the
game once.
two lines.
The first line is an integer n (2<=n<=200), following with n
integers ai(0<=ai<200)
The second line is an
integer m (0<=m<=n), following with m integers
bi(1<=bi<=n), which are the numbers of the special
sides to get another more chance.
money one can get, rounded to exact two digits. If you can get unlimited money,
print inf.
0
4 0 0 0 0
1 3
0.00
similar problems for you: 6263 6262 6261 6260 6259
数学期望公式:E(X)=Xi乘Pi (i=1,2,3.....) X有几个值
给你一个有n个面的筛子,每个面都有一个值,另外有m面如果选中了,可以在投一次,问你期望是多少。
如果没有“m面选中可以在投一次”这一条件,那么期望就是n个面的值之和除以n,记为p=sum/n。
如果有了这个条件,那么只投一次的话,期望就是sum;如果投了两次的话就是p*(m/n);如果投了三次的话就是p*(m/n)^2,无限次就是p*(1+q+q^2+q^3+..+q^k+...)(q=m/n,p=sum/n)
根据等比数列以及无限化简得:sum/(n-m)。
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int i;
int s = ;
int x;
for (i = ; i <= n; i++)
{
cin >> x;
s += x;
}
int m;
cin >> m;
for (i = ; i <= m; i++)
{
cin >> x;
}
if (s == ) cout << "0.00" << endl;//这不能省,因为n==m,s=0时,不是inf
else if (n == m)
cout << "inf" << endl;
else printf("%.2lf\n", (double)s/ (n - m));
}
return ;
}
HDU 4586 Play the Dice(数学期望)的更多相关文章
- UVa 12230 && HDU 3232 Crossing Rivers (数学期望水题)
		
题意:你要从A到B去上班,然而这中间有n条河,距离为d.给定这n条河离A的距离p,长度L,和船的移动速度v,求从A到B的时间的数学期望. 并且假设出门前每条船的位置是随机的,如果不是在端点,方向也是不 ...
 - HDU 4405 飞行棋上的数学期望
		
突然发现每次出现有关数学期望的题目都不会做,就只能找些虽然水但自己还是做不出的算数学期望的水题练练手了 题目大意: 从起点0点开始到达点n,通过每次掷色子前进,可扔出1,2,3,4,5,6这6种情况, ...
 - HDU 4586 Play the Dice (数学,概率,等比公式,极限)
		
题意:给你一个n面的骰子每个面有一个值,然后其中有不同值代表你能获得的钱,然后有m个特殊的面,当你骰到这一面的时候可以获得一个新的机会 问你能得到钱的期望. 析: 骰第一次 sum/n 骰第二 ...
 - 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(概率dp)
		
Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equ ...
 - 概率DP HDU 4586 play the dice
		
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4586 解题思路: 只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加. ...
 - hdu - 3959 Board Game Dice(数学)
		
这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...
 - HDU 1099 Lottery (求数学期望)
		
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1099 Lottery Time Limit: 2000/1000 MS (Java/Others) ...
 - hdu 4586 Play the Dice (概率+等比数列)
		
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...
 
随机推荐
- install ros-indigo-pcl-ros
			
CMake Warning at /opt/ros/indigo/share/catkin/cmake/catkinConfig.cmake: (find_package): Could not fi ...
 - python 删除字典元素
			
myDict = {,,,} print(myDict) if 'a' in myDict: del myDict['a'] print(myDict)
 - 五句话搞定JavaScript作用域【转】
			
JavaScript的作用域一直以来是前端开发中比较难以理解的知识点,对于JavaScript的作用域主要记住几句话,走遍天下都不怕... 一.“JavaScript中无块级作用域” 在Java或C# ...
 - JSP 日期处理
			
JSP 日期处理 使用JSP最重要的优势之一,就是可以使用所有Java API.本章将会详细地讲述Java中的Date类,它在java.util包下,封装了当前日期和时间. Date类有两个构造函数. ...
 - office-word
			
目录(大纲) word中大纲的视图(也就是目录)是根据1/2/3级大纲决定的 格式刷 可以刷成一样的格式,字体,编号以及大纲等等. 主要用于编号和目录,快捷键(ctrl+shift) 编号设置(不建议 ...
 - Leetcode 62
			
//从理解二维dp到简化成一维dp我用了一年的时间class Solution { public: int uniquePaths(int m, int n) { vector<); ;i &l ...
 - 理解 Ruby Symbol (Ruby中的冒号)
			
http://blog.csdn.net/besfanfei/article/details/7966850 一直不明白:的作用 直到看到这篇文章 豁然开朗 处理符号相比字符串,占用更少的资源
 - 在EORow或者VORow中对数据进行重复性校验
			
需求:在设置付款条件时不允许账期+付款方式重复. 由于本次需求仅需要对VO缓存中的数据进行重复性校验,所以仅需进行缓存遍历即可,不需要校验数据库. 方式1,在EORow的进行数据校验. public ...
 - https ddos检测——研究现状
			
from: https://jyx.jyu.fi/bitstream/handle/123456789/52275/1/URN%3ANBN%3Afi%3Ajyu-201612125051.pdf 相关 ...
 - 在TypeScript中使用其他JS框架或库的方法
			
最近刚刚接触TypeScript,感觉非常强大,但是也有一些问题. 比如我们正常写js时,只要把其他js库引入页面,甚至于只要加入到项目中,ReSharper就会自动分析他,并提供语法只能感知,写代码 ...