题目链接

题意:

  给一个质地均匀的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)。

代码:

  

  1. #include <cmath>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <set>
  7. #include <map>
  8. #include <list>
  9. #include <queue>
  10. #include <string>
  11. #include <vector>
  12. #include <fstream>
  13. #include <iterator>
  14. #include <iostream>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. #define INF 0x3f3f3f3f
  19. #define MOD 1000000007
  20. #define eps 1e-6
  21. #define MAXN 100010
  22. #define yy 0.5772156649
  23. double f[MAXN];
  24. void init()
  25. {
  26. f[] = 0.0;
  27. for(int i = ; i < MAXN; i ++)
  28. f[i] = f[i-] + 1.0 / (i * 1.0);
  29. }
  30. double GetExpectation(int n)
  31. {
  32. return n * 1.0 * f[n];
  33. }
  34.  
  35. int main()
  36. {
  37. int T;
  38. int kcase = ;
  39. init();
  40. scanf("%d", &T);
  41. while(T --)
  42. {
  43. int n;
  44. scanf("%d", &n);
  45. printf("Case %d: %.7lf\n", ++ kcase, GetExpectation(n));
  46. }
  47. return ;
  48. }

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. 【转】java.lang.StackOverflowError

    http://blog.csdn.net/g19920917/article/details/8765638 出现一个java.lang.StackOverflowError异常.弄了半天,又是问高手 ...

  2. HDU 2876 Ellipse, again and again

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...

  3. 【转】iOS应用崩溃日志揭秘

    这篇文章还可以在这里找到 英语 If you're new here, you may want to subscribe to my RSS feed or follow me on Twitter ...

  4. git 远程追踪

    $ git branch --set-upstream-to origin/master http://stackoverflow.com/questions/21729560/how-to-make ...

  5. AndroidStudio怎么将开源项目发布到jcenter

    前言 自己在网上搜了一大堆,大体就两种方法,而我选择的是其中代码少的的方法,不过他们或多或少留下了少许的坑,(按他们的方法我是上传成功,但不能发布到jCenter上去,也可能是我自己的问题o(≧v≦) ...

  6. JS如何封装一些列方法为一个对象的操作,然后集中管理这些操作,方便修改和调用

    var Api = { ajax:{ // 添加项目 旧! add_project : function(pro_name, html, css, js,callback) { $.post(&quo ...

  7. MongoDB的查询

    一.Find操作 二.分页和排序 三.游标的使用 一.Find查询 事前准备:插入如下数据 db.Students.insert([ { _id:1, name:"Zhao", a ...

  8. Java随机生成定长纯数字或数字字母混合数

    (转)Java随机生成定长纯数字或数字字母混合数 运行效果图: 具体实现代码

  9. while循环的跳出

    今天在编码时突然产生一个疑问:程序中有一个while循环,循环体执行的是某个附带条件限制的操作.我现在想达到的目的是 => 条件成立,就执行操作,并跳出循环:条件不成立就跳出当次的while循环 ...

  10. SHELL:Find Memory Usage In Linux (统计每个程序内存使用情况)

    转载一个shell统计linux系统中每个程序的内存使用情况,因为内存结构非常复杂,不一定100%精确,此shell可以在Ghub上下载. [root@db231 ~]# ./memstat.sh P ...