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. [问题解决]win10误删启动项(BCD)(HP电脑亲测,无需启动盘,并非重装系统)

    昨天使用easyBCD软件,开始不太懂,手残把win10的引导删除了,后来发现电脑关机总是变成重启,无奈强制关机.今天重启了一下电脑,发现电脑已经无法打开了,这才明白昨天是误删了win10的BCD. ...

  2. js二进制转换十进制

    var a = 1010;alert(a.toString(2)); //转成二进制 alert(parseInt( "101110100 ",2)) ;//转成十进制 null

  3. Python学习札记(四十) 面向对象编程 Object Oriented Program 11

    参考:使用元类 NOTE: type() 1.type()函数可以用于检查一个类或者变量的类型. #!/usr/bin/env python3 class Myclass(object): " ...

  4. Qt5获取网卡/IP等信息

    参考网址:http://blog.csdn.net/wjs1033/article/details/22697063 1.环境 Win7x64.Qt5.5.1(x86).vs2013_ultimate ...

  5. vue 2.5.14以上版本render函数不支持返回字符串

    vue 2.5.14以上版本render函数不再支持直接返回字符串,必须返回数组或vnode节点,如果返回字符串的话,渲染为空.详情可见源码. function createFunctionalCom ...

  6. UVA-11903 Just Finish it up

    题目大意:一个环形跑道上有n个加油站,每个加油站可加a[i]加仑油,走到下一站需要w[i]加仑油,初始油箱为空,问能否绕跑道一圈,起点任选,若有多个起点,找出编号最小的. 题目分析:如果从1号加油站开 ...

  7. wikioi1036 商务旅行 挺水的lca

    链接:http://wikioi.com/problem/1036/ 题意不写了. 思路:很明显找到lca然后用两个点的深度相加-lca的深度就是这一步的最近步数. #include <stdi ...

  8. git 基础入门操作

    前言: 介绍基础的git入门级指令,虽然git指令非常多,但是实际工作中,我们会用到的非常少,小项目中甚至只需要用到2.3个.而且大部分人都会采用gui,而不是每次都打开终端然后输一长串难记的指令. ...

  9. 201621123010 《Java程序设计》第1周学习总结

    1. 本周学习总结 本周主要学习了五个知识点 Java是面向对象的语言 JDK,JRE,JVM的联系 javac及java指令 Java跨平台运行的原理 新概念:类,类是面向对象中的概念 2. 书面作 ...

  10. 让黑白的SecureCRT彩色起来

    让黑白的SecureCRT彩色起来,如图仿真设置如下: