题目链接

题意:

  给一个质地均匀的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. DataGridView减少闪烁的解决办法

    Reducing flicker, blinking in DataGridView http://www.codeproject.com/Tips/390496/Reducing-flicker-b ...

  2. mysql in 的两种使用方法

    简述MySQL 的in 的两种使用方法: 他们各自是在 in keyword后跟一张表(记录集).以及在in后面加上字符串集. 先讲后面跟着一张表的. 首先阐述三张表的结构: s(sno,sname. ...

  3. HDU2029JAVA

    Palindromes _easy version Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  4. Java基础知识强化之IO流笔记28:BufferedOutputStream / BufferedInputStream(字节缓冲区流) 之BufferedOutputStream写出数据

    1. BufferedOutputStream / BufferedInputStream(字节缓冲区流)的概述 通过定义数组的方式确实比以前一次读取一个字节的方式快很多,所以,看来有一个缓冲区还是非 ...

  5. MKServerBuilder.psd1

    MKServerBuilder.psd1 # # Module manifest for module 'MKServerBuilder' # # Generated by: Edward Guan ...

  6. 关于jquery获取服务器端xml数据

    其实这个很简单,但是有时候简单的东西会让你犯一些低级错误. 今天写了个spring mvc 的服务器端接口,主要是用来共享一些数据库数据. 请求字段:http://localhost:8080/XXX ...

  7. 安卓Intent(隐式)

    相对于显式Intent(明确指出了目标组件名称的Intent),隐式Intent,没有明确指出目标组件名称.显式Intent直接用组件的名称定义目标组件,这种方式很直接.但是由于开发人员往往并不清楚别 ...

  8. 验证jquery.validate.js

    <pre>jquery.validate.js使用之自定义表单验证规则,下面列出了一些常用的验证法规则 jquery.validate.js演示查看 <a href="ht ...

  9. C#语法糖之第五篇: 泛型委托- Action<T>

    因为工作的原因(其实还是个人的惰性)昨天没有给大家分享文章,然后这几天也有很多园友也提出了他们报告的意见及指导,再次感谢这些兄弟们的照顾我 和支持,这个分类的文章我当时想的是把我的学习经验和工作中用到 ...

  10. 1. 连接字符串的创建 - Lazy.Framework从零开始设计自己的ORM架构

    开发初衷 注册了博客园已经有几个月了,却从来都没有上来过,本人大概从2010年开始就开始做.NET 方向的开发. 这个是我在博客园发布的第一个帖子. 主要就是说说最近在写的一个ORM架构. 本人接触的 ...