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

Problem Description
There is a dice with n sides, which are numbered from
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.
 
Input
Input consists of multiple cases. Each case includes
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.
 
Output
Just a real number which is the expectations of the
money one can get, rounded to exact two digits. If you can get unlimited money,
print inf.
 
Sample Input
6 1 2 3 4 5 6
0
4 0 0 0 0
1 3
 
Sample Output
3.50
0.00
 
Source
 
Recommend
zhuyuanchen520   |   We have carefully selected several
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(数学期望)的更多相关文章

  1. UVa 12230 && HDU 3232 Crossing Rivers (数学期望水题)

    题意:你要从A到B去上班,然而这中间有n条河,距离为d.给定这n条河离A的距离p,长度L,和船的移动速度v,求从A到B的时间的数学期望. 并且假设出门前每条船的位置是随机的,如果不是在端点,方向也是不 ...

  2. HDU 4405 飞行棋上的数学期望

    突然发现每次出现有关数学期望的题目都不会做,就只能找些虽然水但自己还是做不出的算数学期望的水题练练手了 题目大意: 从起点0点开始到达点n,通过每次掷色子前进,可扔出1,2,3,4,5,6这6种情况, ...

  3. HDU 4586 Play the Dice (数学,概率,等比公式,极限)

    题意:给你一个n面的骰子每个面有一个值,然后其中有不同值代表你能获得的钱,然后有m个特殊的面,当你骰到这一面的时候可以获得一个新的机会 问你能得到钱的期望. 析: 骰第一次     sum/n 骰第二 ...

  4. hdu 4586 Play the Dice 概率推导题

    A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  5. 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 ...

  6. 概率DP HDU 4586 play the dice

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4586 解题思路: 只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加. ...

  7. hdu - 3959 Board Game Dice(数学)

    这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...

  8. HDU 1099 Lottery (求数学期望)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1099 Lottery Time Limit: 2000/1000 MS (Java/Others)   ...

  9. hdu 4586 Play the Dice (概率+等比数列)

    Play the Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To ...

随机推荐

  1. curl使用介绍

    linux curl是通过url语法在命令行下上传或下载文件的工具软件,它支持http,https,ftp,ftps,telnet等多种协议,常被用来抓取网页和监控Web服务器状态. 一.Linux ...

  2. Nginx + LUA下流量拦截算法

    前言 每逢大促必压测,每逢大促必限流,这估计是电商人的常态.每次大促期间,业务流量是平时的几倍十几倍,大促期间大部分业务都会集中在购物车结算,必须限流,才能保证系统不宕机. 限流算法 限流算法一般有三 ...

  3. HDU 3435 A new Graph Game(最小费用流:有向环权值最小覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=3435 题意:有n个点和m条边,你可以删去任意条边,使得所有点在一个哈密顿路径上,路径的权值得最小. 思路: 费用 ...

  4. PowerDesigner16工具学习笔记-创建RQM

    1.点击标准工具条中的

  5. 过滤器系列(二)—— Cuckoo filter

    这一篇讲的是布谷过滤器(cuckoo fliter),这个名字来源于更早发表的布谷散列(cuckoo hash),尽管我也不知道为什么当初要给这种散列表起个鸟名=_= 由于布谷过滤器本身的思想就源自于 ...

  6. hdu——过山车(二分图,匈牙利算法)

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. Integer与int的种种比较你知道多少

    如果面试官问Integer与int的区别:估计大多数人只会说道两点,Ingeter是int的包装类,int的初值为0,Ingeter的初值为null. 但是如果面试官再问一下Integer i = 1 ...

  8. centos6 Nginx+Tomcat负载均衡配置

    一.Nginx简介 Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡,具体简介我就不介绍了百度一下有很多,下面直接进入安装步骤 二.Nginx安装 1.下载N ...

  9. Sonar在ant工程中读取单元测试和覆盖率报告

    虽然sonar支持ant工程的构建,但目前最大的不足是无法在分析过程中产生单元测试和覆盖率报告,这样在sonar面板上覆盖率板块就始终没有数据.但幸运的是,sonar可以读取已经生成好的报告,让报告的 ...

  10. java回收finalize方法的作用(编程思想)

    清理:终结处理和垃圾回收 java有垃圾回收期负责回收无用对象占据的内存资源.但也有这种情况:假定你的对象(并非使用new)获得了一块“特殊”的内存区域,由于垃圾回收期只知道释放那些由new分配的内存 ...