SPOJ 1026 Favorite Dice

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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章