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. Ajax请求304问题

    ajax默认是开启缓存的,所以get请求如果路径一样,会先找缓存,如果缓存存在就用缓存. 解决方案: 1.在修改url为动态变化的,如url后面加一个&timestamp=Date.parse ...

  2. FW: How to use Hibernate Lazy Fetch and Eager Fetch Type – Spring Boot + MySQL

    原帖 https://grokonez.com/hibernate/use-hibernate-lazy-fetch-eager-fetch-type-spring-boot-mysql In the ...

  3. class []的用法

    span[class='test']    =>匹配所有带有class类名test的span标签 span[class *='test']  =>匹配所有包含了test字符串的class类 ...

  4. Python网络编程(Sockets)

    一个简单的服务器 #!/usr/bin/python3 # This is server.py file import socket # create a socket object serverso ...

  5. Linux查看版本当前操作系统内核信息

    1. # uname -a (Linux查看版本当前操作系统内核信息) 输出 Linux xxx --generic #~-Ubuntu SMP Wed Jul :: UTC x86_64 x86_6 ...

  6. 浅析promise

    Promise是一个构造函数,可以通过new 操作符获取一个promise对象,promise者,人如其名也.对,就是承诺.显示生活中,我们承诺别人一件事,一般会在将来某个时间兑现承诺.而 Promi ...

  7. 几句话概括理查德成熟度模型(RESTful)

    近期做的项目中准备引入RESTful风格,特地进行了一些学习,其中比较重点的有一个理查德成熟度模型(Richardson Maturity Model),模型提出了四个等级(0-3),如下图 其中只有 ...

  8. 别名的使用注意,""真坑。

    我们使用别名都是使用as关键字. 大多数时候我们都会省略as关键字,然后后面直接加别名就好了.我的习惯是别名用双引号括起来. 今天因为这个习惯坑了我一大波 首先oracle的别名的规则: AS 别名 ...

  9. 【转】Linux下同时复制多个文件

    一.命令方法 1.使用cp命令 cp /home/usr/dir/{file1,file2,file3,file4} /home/usr/destination/ 需要注意的是这几个文件之间不要有空格 ...

  10. Struts2中StrutsRequestWrapper类

    该类可获取一些请求地址,在自定义struts2标签时用到 //获取值栈 Map cont= this.getStack().getContext(); StrutsRequestWrapper req ...