HDU 4586 Play the Dice 概率dp+等比数列 级数
2016-05-07 21:02
417 查看
C - Play the Dice
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice HDU
4586
Appoint description:
System Crawler (2016-05-07)
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 a i(0<=a i<200)
The second line is an integer m (0<=m<=n), following with m integers b i(1<=b i<=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
给你一个n面的骰子每个面有一个值然后其中有不同值代表你能获得的钱
然后有m个特殊的面——当你骰到这一面的时候可以获得一个新的机会
问你能得到钱的期望,
骰第一次 sum/n
骰第二次 sum/n*(m/n)
骰第三次 sum/n*(m/n)*(m/n)
骰第四次 sum/n*(m/n)*(m/n)*(m/n)
.
.
.
.
骰第k次
sum/n*(m/n)^k
即 sum/n*(1+q+q^2+q^3+……+q^k) q=m/n k=inf
所以 sum/n*(1/(1-m/n)) = (sum/n)*(n/n-m) =sum/n-m
那么 n=m时候期望无限大
notice sum等于0的时候直接输出 0.00///我不知道为什么
ACcdoe:
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice HDU
4586
Appoint description:
System Crawler (2016-05-07)
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 a i(0<=a i<200)
The second line is an integer m (0<=m<=n), following with m integers b i(1<=b i<=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
给你一个n面的骰子每个面有一个值然后其中有不同值代表你能获得的钱
然后有m个特殊的面——当你骰到这一面的时候可以获得一个新的机会
问你能得到钱的期望,
骰第一次 sum/n
骰第二次 sum/n*(m/n)
骰第三次 sum/n*(m/n)*(m/n)
骰第四次 sum/n*(m/n)*(m/n)*(m/n)
.
.
.
.
骰第k次
sum/n*(m/n)^k
即 sum/n*(1+q+q^2+q^3+……+q^k) q=m/n k=inf
所以 sum/n*(1/(1-m/n)) = (sum/n)*(n/n-m) =sum/n-m
那么 n=m时候期望无限大
notice sum等于0的时候直接输出 0.00///我不知道为什么
ACcdoe:
#include <cstdio> #include <cmath> #define maxn 202 #define eps 1e-8 int p[maxn]; int main(){ int n,m; while(~scanf("%d",&n)){ int sum=0; for(int i=1;i<=n;++i){ scanf("%d",&p[i]); sum+=p[i]; } scanf("%d",&m); int t; for(int i=1;i<=m;++i)scanf("%d",&t); if(sum==0){ printf("0.00\n"); continue; } if(n==m) puts("inf"); else printf("%0.2lf\n",(double)sum/(n-m)); } return 0; }
相关文章推荐
- 超链接a提交表单
- Windows驱动开发(7) - DEVICE_OBJECT结构体
- 对照Java学习Swift--构造过程(Initialization)
- MySQL分区表
- 通过直方图比较图像相似度
- 【Android Native Code开发系列】六 一个Native Service的完整示例
- Java线程详解
- NOIP2012day1题解
- 介绍const
- constexpr 和 inline
- AndroidImageSlider超炫的轮播图效果
- 前端学习总结(三)javascript——前端世界的精髓所在
- Spring记录之Spring的基本概念
- IOS9中联系人对象的使用及增删改查操作的函数封装
- iOS 杂笔-21(self.name = “object” 和 _name =”object” 有什么不同?)
- 【Android Native Code开发系列】 五 运行、调试编译的Native Code项目
- 第十四章 springboot + profile(不同环境读取不同配置)
- MySQL免安装版的下载与文件配置
- bzoj4403 两个串
- 如何将源代码编译后的文件(lib库/bin/jar/apk等)编译到android中