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 ...
随机推荐
- Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...
- Yii框架(二)Model处理数据
熟悉php的autoload机制,自己实现一个autoload函数 一.复习框架: basic/ 应用根目录 composer.json Composer 配置文件, 描述包信息 config/ 包含 ...
- python 通过列表元素值截取列表并获取长度
def count_range_in_list(li, min, max): ctr = for x in li: if min <= x <= max: ctr += return ct ...
- python 字符串压缩
import zlib s = b'witch which has which witches wrist watch' print(len(s)) t = zlib.compress(s) prin ...
- Java中的String和StringBuffer
在任何编程语言中,字符串都是我们编写程序时不可避免要用到的常用的数据类型之一. 对于Java初学者而言,当谈到String和StringBuffer的区别时,通常都会有些困惑. 而要弄清楚两者之间的区 ...
- java中interrupt、join、sleep、notify、notifyAll、wait详解
首先介绍一下中断概念:举个例子容易理解一点 例子:假如你正在给朋友写信,电话铃响了.这时,你放下手中的笔,去接电话.通话完毕,再继续写信.这个例子就表现了中断及其处理过程:电话铃声使你暂时中止当前的工 ...
- Confluence 6 创建一个用户宏
如果你想创建自定义的宏的话,用户宏能够帮你完成这个任务.这个可以在你系统中应用特定的操作,比如说应用自定义格式等. 用户用是在 Confluence 创建和和管理的,你需要有一定的编码基础才可以. 你 ...
- xssProject在java web项目中应用
注:转载http://337027773.blog.163.com/blog/static/54376980201451133534157/ 1.项目引入xssProtect-0.1.jar.antl ...
- Dubbo原理简介、与Zookeeper整合利用
官方文档:http://dubbo.io/books/dubbo-user-book/ Dubbo的简单介绍 Dubbo是一个分布式服务框架,架构如图: 节点角色说明: Provider: 暴露服务的 ...
- ENUMSTXT.H中的指针数组
/************************************************************************ ...