【HDU5159】【BestCoderRound26.1002】Card

来源:互联网 发布:淘宝网站营销策划方案 编辑:程序博客网 时间:2024/06/15 06:38


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
22 33 3
 

Sample Output
Case #1: 2.625Case #2: 4.222
Hint
For 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,2So the expectation is (1+3+3+3+3+3+3+2)/8=2.625
翻译题目

问题描述
桌子上有a张牌,每张牌从1到a编号,编号为i(1<=i<=a)的牌上面标记着分数i , 每次从这a张牌中随机抽出一张牌,然后放回,执行b次操作,记第j次取出的牌上面分数是 Sj , 问b次操作后不同种类分数之和的期望是多少。
输入描述
多组数据,第一输入数据组数T ,接下来T行,每行两个整数a,b以空格分开[参数说明]所有输入均为整数1<=T<=5000001<=a<=1000001<=b<=5
输出描述
输出答案占一行,输出格式为 Case #x: ans, x是数据编号从1开始,ans是答案,精确到小数点后3位。看样例可以得到更多信息。
输入样例
22 33 3
输出样例
Case #1: 2.625Case #2: 4.222提示:对于第一组数据所有牌型的组合为(1, 1, 1),(1,1,2),(1,2,1),(1,2,2),(2,1,1),(2,1,2),(2,2,1),(2,2,2)对于(1,1,1)这个组合,他只有一种数字,所以不同数字之和为1而对于(1,2,1)有两种不同的数字,即1和2,所以不同数字之和是3。所以对应组合的不同数字之和为1,3,3,3,3,3,3,2所以期望为(1+3+3+3+3+3+3+2)/8=2.625

数学期望题。

虽然之前学过期望,学过期望的线性性质,会一点概率,但是这次比赛做这个题来看发现自己其实还是学的不到功夫啊。。。

看到题解的一瞬间就明白了

但是比赛过程中就是没想出来

哎。。。。

设Xi代表分数为i的牌在b次操作中是否被选到,Xi=1为选到,Xi=0为未选到那么期望EX=1*X1+2*X2+3*X3+…+x*XxXi在b次中被选到的概率是1-(1-1/x)^b那么E(Xi)= 1-(1-1/x)^b那么EX=1*E(X1)+2*E(X2)+3*E(X3)+…+x*E(Xx)=(1+x)*x/2*(1-(1-1/x)^b)————赛后题解
其实明明能看懂,能明白的QAQ

这么蛋疼的题

代码就只有这么短= =

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int main(){int T,a,b;scanf("%d",&T);for (int i=1;i<=T;i++){scanf("%d%d",&a,&b);double a1=1-pow(1-1.0/a,b);double x=a;double ans=x*(x+1)/2*a1;printf("Case #%d: %.3lf\n",i,ans);}}


0 0
原创粉丝点击