LightOJ_1248 Dice (III)
题意:
给一个质地均匀的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)的更多相关文章
- [LOJ 1248] Dice (III)
G - Dice (III) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...
- LightOJ - 1248 Dice (III) —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1248 1248 - Dice (III) PDF (English) Statistics Forum Tim ...
- LightOJ 1248 Dice (III) (期望DP / 几何分布)
题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...
- 1248 - Dice (III)
1248 - Dice (III) PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- Dice (III) 概率dp
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...
- LightOJ 1248 Dice (III)
期望,$dp$. 设$dp[i]$表示当前已经出现过$i$个数字的期望次数.在这种状态下,如果再投一次,会出现两种可能,即出现了$i+1$个数字以及还是$i$个数字. 因此 $dp[i]=dp[i]* ...
- LightOj 1248 - Dice (III)(几何分布+期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1248 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望 ...
- LightOJ 1248 Dice (III) (水题,期望DP)
题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...
随机推荐
- [C#] 常用工具类——加密解密类
using System; using System.Configuration; using System.Collections.Generic; using System.Text; using ...
- 用Ajax去读取服务器端的XML格式的数据
<html> <head></head> <script type="text/javascript"> /*---定义一个全局变量 ...
- BZOJ 2754([SCOI2012]喵喵叫的星球-统计序列的后缀阵列中子序列出现次数)
2754: [SCOI2012]喵喵叫的星球 Time Limit: 20 Sec Memory Limit: 128 MB Submit: 805 Solved: 380 [id=2754&qu ...
- 【转】iOS应用崩溃日志揭秘2
这篇文章还可以在这里找到 英语 场景 4: 吃棒棒糖时闪退! 用户邮件说, "当rage master吃棒棒糖时应用就闪退-" 另一用户说, "我让rage master ...
- magic_quotes_runtime(魔术引号开关)
我们可以通过以下代码来探测php环境中magic_quotes_runtime是否开启: magic_runtime.php 源代码如下: <?php //当magic_quotes_runti ...
- iOS监听电话事件
项目上有个需求,要求打完电话后加积分. 首先导入这两个头文件: #import <CoreTelephony/CTCallCenter.h> #import <CoreTelepho ...
- 路E施工管理ERP系统
前 景 目前公路工程由于点多.线长.面广.周期久.投资大等原因,管理很难到位,施工过程中存在着大量问题: 规章制度欠缺或不健全,即便是有好的规章制度,在施工过程中也往往形同虚设,不能与现场施 ...
- DedeCMS文章标题前增加所属栏目名称链接
问题描述:在调用文章标题的时候,我想实现这样的形式:“[国内新闻]站长无忧真的是一个不错的站”,其中“国内新闻”是标题的所属栏目,并且加链接: 解决方法: [field:typelink /]这 ...
- 如何打包成jar包自己看呢?
第一步:选择你要导出的部分 第二步:
- WebStrom安装了angularjs插件,但是没有语法提示
你必须要将angular.js文件放在当前工程下才能激活代码提示功能.