第六周 E题 期望.....

Description

Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the dice is fair, that means when you throw the dice, the probability of occurring any face is equal.

For example, for a fair two sided coin, the result is 3. Because when you first throw the coin, you will definitely see a new face. If you throw the coin again, the chance of getting the opposite side is 0.5, and the chance of getting the same side is 0.5. So, the result is

1 + (1 + 0.5 * (1 + 0.5 * ...))

= 2 + 0.5 + 0.52 + 0.53 + ...

= 2 + 1 = 3

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 105).

Output

For each case, print the case number and the expected number of times you have to throw the dice to see all its faces at least once. Errors less than10-6 will be ignored.

Sample Input

5

1

2

3

6

100

Sample Output

Case 1: 1

Case 2: 3

Case 3: 5.5

Case 4: 14.7

Case 5: 518.7377517640

题意:给你一个n面的骰子,要你求,这个骰子每面出现一次的期望....

题解:第i面的骰子的期望就是n/i

代码如下:

 #include <stdio.h>
int main()
{
int T,N=;
scanf("%d",&T);
while(T--)
{
N++;
double n;
scanf("%lf",&n);
double ans=;
for(double i=1.0;i<=n;i++)
ans+=n/i;
printf("Case %d: %.10lf\n",N,ans);
}
return ;
}
上一篇:【03NOIP普及组】麦森数(信息学奥赛一本通 1925)(洛谷 1045)


下一篇:cocos2d-x博客网站推荐和牛逼的教程