题目链接

题意:

  给一个质地均匀的n的骰子, 求投掷出所有点数至少一次的期望次数。

思路:

  这就是一个经典的邮票收集问题(Coupon Collector Problem)。

  投掷出第一个未出现的点数的概率为n/n = 1, 因为第一次投掷必然是未出现的。

  第二个未出现的点数第一次出现的概率为 (n - 1) / n,因为有一个已经投掷出现过。

  第i个未出现的点数第一次出现的概率为 (n - i) / i, 这满足几何分布。

  其期望E = 1/p

  所以期望为n *(1 + 1 / 2 + 1 / 3 + ... 1 / n)。

代码:

  

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 100010
#define yy 0.5772156649
double f[MAXN];
void init()
{
f[] = 0.0;
for(int i = ; i < MAXN; i ++)
f[i] = f[i-] + 1.0 / (i * 1.0);
}
double GetExpectation(int n)
{
return n * 1.0 * f[n];
} int main()
{
int T;
int kcase = ;
init();
scanf("%d", &T);
while(T --)
{
int n;
scanf("%d", &n);
printf("Case %d: %.7lf\n", ++ kcase, GetExpectation(n));
}
return ;
}

LightOJ_1248 Dice (III)的更多相关文章

  1. [LOJ 1248] Dice (III)

    G - Dice (III) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Descri ...

  2. LightOJ - 1248 Dice (III) —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1248 1248 - Dice (III)    PDF (English) Statistics Forum Tim ...

  3. LightOJ 1248 Dice (III) (期望DP / 几何分布)

    题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...

  4. 1248 - Dice (III)

    1248 - Dice (III)   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given ...

  5. LightOJ 1248 Dice (III) 概率

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

  6. Dice (III) 概率dp

    #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...

  7. LightOJ 1248 Dice (III)

    期望,$dp$. 设$dp[i]$表示当前已经出现过$i$个数字的期望次数.在这种状态下,如果再投一次,会出现两种可能,即出现了$i+1$个数字以及还是$i$个数字. 因此 $dp[i]=dp[i]* ...

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

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1248 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望 ...

  9. LightOJ 1248 Dice (III) (水题,期望DP)

    题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...

随机推荐

  1. 程序猿的编程神器 - vim

    一.官方文档: 当你首次安装好 Vim 之后.能够用 :help tutor 或者 :help tutor@cn 命令.进入一个30分钟的 Vim 新手教程.你也能够下载一个 Vim Document ...

  2. 晕,hibernate 的 merge和cascade="all-delete-orphan"要慎重合在一起使用

    遇到一个比较后悔莫及事情,使用了hibernate 的 merge和cascade="all-delete-orphan" ,子表数据被删除了. 1.使用cascade=" ...

  3. JSP中嵌入java代码的标签方式(转)

    (1)声明变量或方法 :  <%! 声明; %> :慎重使用,因为此方法定义的是全局变量 (2)java片段(scriptlet):  <% java代码; %> (3)表达式 ...

  4. WIN32 根据程序名(映像名称)终止外部程序

    场景: 1.有时候需要调用外部程序,但是外部程序有可能崩溃挂起,这样这个进程就没法结束,所以再在下次调用前需要先结束之前调用的. 2.没考虑到权限问题,应该是只能终止当前用户启动的进程. #inclu ...

  5. qt 与mysql建立交互式连接

    void QSqlDatabase::setConnectOptions(const QString & options = QString())Sets database-specific ...

  6. 错误ERROR datanode.DataNode (DataXceiver.java:run(278)) - hadoop07:50010DataXceiver error processing unknown operation src:127.0.0.136479 dst:127.0.0.150010

    原因: Ambari 每分钟会向datanode发送"ping"连接一下去确保datanode是正常工作的.否则它会触发alert.但是datanode并没有处理空内容的逻辑,所以 ...

  7. linux shell wc 命令

    1. 语法与选项 Short Option Long Option Option Description -c –bytes print the byte counts -m –chars print ...

  8. android UI生成器

    可根据选择的效果生成资源 http://jgilfelt.github.io/android-actionbarstylegenerator/#name=example&compat=sher ...

  9. Js 上传文件 页面不刷新

    html控件代码: <form id="form1"> <p><input type="file" name="mfil ...

  10. Java验证码代码

    public class VerifyCodeController { private int width = 90;//定义图片的width private int height = 20;//定义 ...