HDU 5159 Card(数学期望)
2015-09-02 18:18
357 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5159
Problem Description
There are x cards on the desk, they are numbered from 1 to x. The score of the card which is numbered i(1<=i<=x) is i. Every round BieBie picks one card out of the x cards,then puts it back. He does the same operation for b rounds. Assume that the score of
the j-th card he picks is Sj .
You are expected to calculate the expectation of the sum of the different score he picks.
Input
Multi test cases,the first line of the input is a number T which indicates the number of test cases.
In the next T lines, every line contain x,b separated by exactly one space.
[Technique specification]
All numbers are integers.
1<=T<=500000
1<=x<=100000
1<=b<=5
Output
Each case occupies one line. The output format is Case #id: ans, here id is the data number which starts from 1,ans is the expectation, accurate to 3 decimal places.
See the sample for more details.
Sample Input
Sample Output
题意:
X张卡牌,标号分别为1,2,…,X,,每张牌的分数为对应的序号,随机抽取卡牌b次,每次都放回,记录下卡牌的分数,求抽取到不同卡牌的期望
思路:
和的期望
= 各部分期望的和。
E = E(1) + E(2) + ... + E(x) ;
每张牌每一轮抽到的概率为 1/x ;
每张牌每一轮不抽到的概率为 1-1/x ;
每张牌b次操作后都没抽到的概率为 (1-1/x)^b ;
每张牌b次操作后有被抽到的概率为 p = 1-(1-1/x)^b ;
所以每个数的期望也是 i*( 1-(1-1/x)^b )
Card
Problem DescriptionThere are x cards on the desk, they are numbered from 1 to x. The score of the card which is numbered i(1<=i<=x) is i. Every round BieBie picks one card out of the x cards,then puts it back. He does the same operation for b rounds. Assume that the score of
the j-th card he picks is Sj .
You are expected to calculate the expectation of the sum of the different score he picks.
Input
Multi test cases,the first line of the input is a number T which indicates the number of test cases.
In the next T lines, every line contain x,b separated by exactly one space.
[Technique specification]
All numbers are integers.
1<=T<=500000
1<=x<=100000
1<=b<=5
Output
Each case occupies one line. The output format is Case #id: ans, here id is the data number which starts from 1,ans is the expectation, accurate to 3 decimal places.
See the sample for more details.
Sample Input
2 2 3 3 3
Sample Output
Case #1: 2.625 Case #2: 4.222 HintFor the first case, all possible combinations BieBie can pick are (1, 1, 1),(1,1,2),(1,2,1),(1,2,2),(2,1,1),(2,1,2),(2,2,1),(2,2,2) For (1,1,1),there is only one kind number i.e. 1, so the sum of different score is 1. However, for (1,2,1), there are two kind numbers i.e. 1 and 2, so the sum of different score is 1+2=3. So the sums of different score to corresponding combination are 1,3,3,3,3,3,3,2 So the expectation is (1+3+3+3+3+3+3+2)/8=2.625
题意:
X张卡牌,标号分别为1,2,…,X,,每张牌的分数为对应的序号,随机抽取卡牌b次,每次都放回,记录下卡牌的分数,求抽取到不同卡牌的期望
思路:
和的期望
= 各部分期望的和。
E = E(1) + E(2) + ... + E(x) ;
每张牌每一轮抽到的概率为 1/x ;
每张牌每一轮不抽到的概率为 1-1/x ;
每张牌b次操作后都没抽到的概率为 (1-1/x)^b ;
每张牌b次操作后有被抽到的概率为 p = 1-(1-1/x)^b ;
所以每个数的期望也是 i*( 1-(1-1/x)^b )
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int main() { int t,k=1; scanf("%d",&t); double x,b; while(t--) { scanf("%lf%lf",&x,&b); double ans=0; double p=1-pow((1-1.0/x),b); double n=(1+x)*x*1.0/2; ans=n*p; printf("Case #%d: %.3lf\n",k++,ans); } return 0; }
相关文章推荐
- 代理模式之JDK动态代理
- java 获取时间
- 在HTML中打出人民币符号和对勾符号
- Linux主要shell命令详解
- 反射
- 三分钟理解“抽象工厂模式”——设计模式轻松掌握
- windows64位下系统文件提示找不到
- Python Tkinter Entry和Text的添加与使用
- 三分钟理解“抽象工厂模式”——设计模式轻松掌握
- 在HTML中打出人民币符号和对勾符号
- 缓存与饼干,spring mvc使用ehcache
- 学习方法
- vi & vim 插入 删除 修改 文本
- wildfly8 Log包冲突和file.encoding调整
- NSAttributedString
- CloseHandle()函数的使用?
- jquery cookie插件用法
- rpm
- document.body.scrollTop用法
- Boost 库应用——智能指针(一)