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 面的期望是多少,然后两种选择一种是看到新 ...
随机推荐
- 【转】java.lang.StackOverflowError
http://blog.csdn.net/g19920917/article/details/8765638 出现一个java.lang.StackOverflowError异常.弄了半天,又是问高手 ...
- HDU 2876 Ellipse, again and again
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...
- 【转】iOS应用崩溃日志揭秘
这篇文章还可以在这里找到 英语 If you're new here, you may want to subscribe to my RSS feed or follow me on Twitter ...
- git 远程追踪
$ git branch --set-upstream-to origin/master http://stackoverflow.com/questions/21729560/how-to-make ...
- AndroidStudio怎么将开源项目发布到jcenter
前言 自己在网上搜了一大堆,大体就两种方法,而我选择的是其中代码少的的方法,不过他们或多或少留下了少许的坑,(按他们的方法我是上传成功,但不能发布到jCenter上去,也可能是我自己的问题o(≧v≦) ...
- JS如何封装一些列方法为一个对象的操作,然后集中管理这些操作,方便修改和调用
var Api = { ajax:{ // 添加项目 旧! add_project : function(pro_name, html, css, js,callback) { $.post(&quo ...
- MongoDB的查询
一.Find操作 二.分页和排序 三.游标的使用 一.Find查询 事前准备:插入如下数据 db.Students.insert([ { _id:1, name:"Zhao", a ...
- Java随机生成定长纯数字或数字字母混合数
(转)Java随机生成定长纯数字或数字字母混合数 运行效果图: 具体实现代码
- while循环的跳出
今天在编码时突然产生一个疑问:程序中有一个while循环,循环体执行的是某个附带条件限制的操作.我现在想达到的目的是 => 条件成立,就执行操作,并跳出循环:条件不成立就跳出当次的while循环 ...
- SHELL:Find Memory Usage In Linux (统计每个程序内存使用情况)
转载一个shell统计linux系统中每个程序的内存使用情况,因为内存结构非常复杂,不一定100%精确,此shell可以在Ghub上下载. [root@db231 ~]# ./memstat.sh P ...