LightOJ 1248 Dice (III) [期望]
来源:互联网 发布:淘宝上属性和属性值 编辑:程序博客网 时间:2024/05/16 06:52
点击打开题目
题意: 给你一个n个点的色子, 掷一次色子获得每个点数的概率相同, 求得到所有点数时掷色子次数的期望值;
思路: 假设已经有k个点数已经出现过, 则掷下一次可能得到未出现过的点数, 期望为1, 也可能得到已出现过的点数, 概率为k / n, 若得到已出现的点数, 则继续掷色子, 所以期望
E = 1 + k / n (1 + k / n (1 + n / k * (...)))
= 1 + k / n + (k / n) ^ 2 + (k / n) ^ 3 + ...
= 1 + k / (n - k)
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<queue>#include<vector>#include<cmath>#include<functional>using namespace std;typedef long long ll;const int maxn = 1e5 + 10;const double eps = 1e-9;const int inf = 1 << 30;int main() { int t, v = 1, n; scanf("%d", &t); while(t--) { scanf("%d", &n); double ans = 0; for(int k = 0; k < n; k++) { ans += 1 + 1.0 * k / (n - k); } printf("Case %d: %.8f\n", v++, ans); } return 0;}
阅读全文
0 0
- LightOJ 1248 Dice (III) [期望]
- LightOJ - 1248 Dice (III) 期望 + dp
- lightoj 1248 Dice (III)(几何分布+期望)
- LightOJ-1248-Dice (III) (数学期望)
- LightOJ 1248 Dice (III)
- lightoj 1248 Dice (III)
- LightOJ 1248 Dice (III)
- LightOJ 1248Dice (III)
- light oj 1248 - Dice (III)(期望)
- lightOJ 1248 - Dice (III) 概率DP
- lightOj 1248 Dice (III) 概率公式
- 【LightOJ 1248】Dice (III)(概率DP)
- Dice (III) LightOJ
- Dice (III) LightOJ
- Lightoj 1248(求期望)
- 期望 -LightOJ 1248
- Light OJ 1248 - Dice (III) 概率DP
- hdu 4652 Dice(期望)
- 依据XML定义报文格式解析数据
- ALV报表复制程序标准工具栏
- Intellij idea移植Cordova的Android平台代码至Android Studio的一些问题
- [Vue warn]: Avoid mutating a prop directly since the value will be overwritten
- java 实现的excel数据导入及导入模板下载
- LightOJ 1248 Dice (III) [期望]
- Find The Multiple POJ
- LaTeX公式居中问题
- 【机器学习】【计算机视觉】数据挖掘测试数据集大全
- Android权限——安装apk后权限详情界面所需权限默认开启状态
- C语言 gets()和scanf()函数的区别
- 足球视频小程序开发之页面数据绑定及跳转传参
- 二维线段树 模板题
- 输出100至200之间的所有素数