Description
BuggyD loves to carry his favorite die around. Perhaps you wonder why it's his favorite? Well, his die is magical and can be transformed into an N-sided unbiased die with the push of a button. Now BuggyD wants to learn more about his die, so he raises a question:
What is the expected number of throws of his die while it has N sides so that each number is rolled at least once?
Input
The first line of the input contains an integer t, the number of test cases. t test cases follow.
Each test case consists of a single line containing a single integer N (1 <= N <= 1000) - the number of sides on BuggyD's die.
Output
For each test case, print one line containing the expected number of times BuggyD needs to throw his N-sided die so that each number appears at least once. The expected number must be accurate to 2 decimal digits.
Sample Input
Input: 2 1 12 Output: 1.00 37.24
不会只能怪高中老师了。从已经出现i面变成已经出现i+1面的期望投掷次数是N/(N-i)。
今天一开始被这道题坑了一个小时,OMG,我居然想到了旋轮线什么的~~~
来张图纪念一下上午的坑爹想法:
这个问题其实很著名,叫做 conpon collector problem,可以去维基看一看,讲的很详细。
#include <cstdio>
int main(){
int kase,n;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
double ans = 0;
for(int i = 1;i <= n;i++) ans += (n+0.0)/(i+0.0);
printf("%.2f\n",ans);
}
return 0;
}