Dice (III) LightOJ - 1248

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 than 10-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

http://blog.csdn.net/u014552756/article/details/51462135

突然发现我的概率之菜

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 const int maxn=1e5+5;
 5
 6 int kase,n;
 7 double dp[maxn];
 8
 9 int main()
10 {   cin>>kase;
11     for(int t=1;t<=kase;t++){
12         cin>>n;
13         dp[1]=1.0;
14         for(int i=2;i<=n;i++) dp[i]=dp[i-1]+double(n)/(double(i)-1.0);
15         printf("Case %d: %lf\n",t,dp[n]);
16     }
17     return 0;
18 }
时间: 2024-10-13 22:25:32

Dice (III) LightOJ - 1248的相关文章

F - Dice (III) LightOJ - 1248

F - Dice (III) LightOJ - 1248 题目描述: 掷出有n面的色子的全部面,求他的期望. 分析: 期望dp,假设掷出i面,dp[i]表示掷出i面的期望.每次会掷出2种情况:1.掷出不同的面,转移到i+1面,概率为(n-i)/n.2.掷出相同的,状态还是i面,概率为i/n. 且花费为1(每次要投一次).dp方程:dp[i]=( dp[i+1]+1 ) * (n-i)/n+( dp[i]+1 ) *i/n,化简为dp[i]=dp[i+1]+1+i/(n-i).(期望dp要逆推)

[lLOJ 1248] Dice (III)

G - Dice (III) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu 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

LightOj 1248 - Dice (III)(几何分布+期望)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1248 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望: 第一个面第一次出现的概率是p1 n/n; 第二个面第一次出现的概率是p2 (n-1)/n; 第三个面第一次出现的概率是p3 (n-2)/n; ... 第 i 个面第一次出现的概率是pi (n-i+1)/n; 先看一下什么是几何分布: 几何分布: 在第n次伯努利试验中,试验 k 次才得到第一次成功

LightOJ 1248 - Dice (III) 给一个质地均匀的n的骰子, 求投掷出所有点数至少一次的期望次数。(概率)

题意:http://www.lightoj.com/volume_showproblem.php?problem=1248 投掷出第一个未出现的点数的概率为n/n = 1, 因为第一次投掷必然是未出现的. 第二个未出现的点数第一次出现的概率为 (n - 1) / n,因为有一个已经投掷出现过. 第i个未出现的点数第一次出现的概率为 (n - i) / i, 这满足几何分布. 其期望E = 1/p 所以期望为n *(1 + 1 / 2 + 1 / 3 + ... 1 / n). #include<

LightOJ 1248 Dice (III)

期望,$dp$. 设$dp[i]$表示当前已经出现过$i$个数字的期望次数.在这种状态下,如果再投一次,会出现两种可能,即出现了$i+1$个数字以及还是$i$个数字. 因此 $dp[i]=dp[i]*i/n+dp[i+1]*(n-i)/n+1$,即$dp[i]=dp[i+1]+n/(n-i)$,$dp[n]=0$,推出$dp[0]$即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio

LightOJ - 1248 Dice (III) 期望 + dp

题目大意:给出一个n面的色子,问看到每个面的投掷次数期望是多少 解题思路:水题啊,竟然被卡了那么久,也是醉了,给题目所给的那个样例误导了...不怪那个 怪自己太弱了,还得继续训练啊... 设dp[i]表示扔到i个不同面的期望,那么 dp[i + 1] = i / n * dp[i + 1] + (n - i) / n * dp[i] + 1 整理得 dp[i + 1] = n / (n - i) + dp[i] + 1 #include<cstdio> #define maxn 100010

【非原创】LightOj 1248 - Dice (III)【几何分布+期望】

学习博客:戳这里 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望: 第一个面第一次出现的概率是p1 n/n; 第二个面第一次出现的概率是p2 (n-1)/n; 第三个面第一次出现的概率是p3 (n-2)/n; ... 第 i 个面第一次出现的概率是pi (n-i+1)/n; 先看一下什么是几何分布: 几何分布: 在第n次伯努利试验中,试验 k 次才得到第一次成功的机率为p.详细的说是:前k-1次皆失败,第k次成功的概率为p. 几何分布的期望E(X) = 1/p;

1248 - Dice (III)

  PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB 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 m

light oj 1248 - Dice (III)(期望)

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.