题目链接

题意:

  给一个质地均匀的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. WebService基于SoapHeader实现安全认证(一)

    本文转载:http://www.cnblogs.com/houleixx/archive/2009/08/22/webservice-soapheader-security.html WebServi ...

  2. cocos2d-x 3.0正式版 环境搭建 (解决载入失败,未能载入XXX包)

    cocos2d-x 3.0正式版最终公布了~ 等了好久~ 废话不多说,直接写方法. 1.下载安装vc2012 ,我用的是旗舰版,传送门:点击打开链接 2.下载cocos2d-x 3.0正式版,传送门: ...

  3. web配置nagios工具

    Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员, ...

  4. FastDFS分布文件系统[转]

    FastDFS是为互联网应用量身定做的一套分布式文件存储系统,非常适合用来存储用户图片.视频.文档等文件.对于互联网应用,和其他分布式文件系统相比,优势非常明显.具体情况大家可以看相关的介绍文档,包括 ...

  5. Android 中 更新视图的函数ondraw() 和dispatchdraw()的区别

    绘制VIew本身的内容,通过调用View.onDraw(canvas)函数实现 绘制自己的孩子通过dispatchDraw(canvas)实现 View组件的绘制会调用draw(Canvas canv ...

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

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

  7. Chapter 2 - How to Add a sprite

    Chapter 2 - How to Add a sprite 1. Add image resources 1.1add resources on win32 2. Add a sprite TIP ...

  8. iOS 9 关键字的简单使用

    前言: 在iOS 9 苹果推出了很多关键字, 目的其实很明确, 主要就是提高开发人员的效率, 有益于程序员之间的沟通与交流, 在开发中代码更加规范! 1. nullable 与 nonnull nul ...

  9. Properties文件,Data,Calendar类的使用

    package cn.hncu.day9; import java.io.FileInputStream;import java.io.FileNotFoundException;import jav ...

  10. Android(java)学习笔记184:生成 4种 不同权限的文件

    1.首先我们编写一个生成 4种 不同权限的文件的程序案例: (1)首先是activity_main.xml文件: <RelativeLayout xmlns:android="http ...