Day11 - B - Dice (III) LightOJ - 1248
设dp_i为已经出现了i面,需要的期望次数,dp_n=0
那么dp_i= i/n*dp_i + (n-i)/n*dp_(i+1) + 1
现在已经i面了,i/n的概率再选择一次i面,(n-i)/n的概率选到新的一面,分别乘其期望次数,并且这次丢过,所以+1
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii; const int maxm = 1e5+;
double dp[maxm]; void run_case() {
int n; cin >> n;
dp[n] = ;
for(int i = n-; i >= ; --i)
dp[i] = dp[i+] + (double)n / (n-i);
cout << dp[] << "\n";
} int main() {
ios::sync_with_stdio(false), cin.tie();
cout.flags(ios::fixed);cout.precision();
int t; cin >> t;
//while(t--)
for(int i = ; i <= t; ++i) {
cout << "Case " << i << ": ";
run_case();
}
cout.flush();
return ;
}
Day11 - B - Dice (III) LightOJ - 1248的更多相关文章
- LightOJ 1248 Dice (III) (期望DP / 几何分布)
题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...
- LightOJ - 1248 Dice (III) —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1248 1248 - Dice (III) PDF (English) Statistics Forum Tim ...
- 1248 - Dice (III)
1248 - Dice (III) PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given ...
- [LOJ 1248] Dice (III)
G - Dice (III) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...
- Brush (III) LightOJ - 1017
Brush (III) LightOJ - 1017 题意:有一些点,每刷一次可以将纵坐标在区间(y1,y1+w)范围内的所有点刷光,y1为任何实数.最多能刷k次,求最多共能刷掉几个点. 先将点按照纵 ...
- LightOj 1248 - Dice (III)(几何分布+期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1248 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望 ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- LightOJ 1248 Dice (III)
期望,$dp$. 设$dp[i]$表示当前已经出现过$i$个数字的期望次数.在这种状态下,如果再投一次,会出现两种可能,即出现了$i+1$个数字以及还是$i$个数字. 因此 $dp[i]=dp[i]* ...
- LightOJ 1248 Dice (III) (水题,期望DP)
题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...
随机推荐
- win10 superfetch 使系统变慢
win10 superfetch是干什么的? 时间:2018-12-28 来源:莫回首系统 作者:win7 很多用户喜欢关注CPU的运行状态,来保障系统的运行速度不受影响,今早,有ghost win1 ...
- bugku 求getshell
要修改三个地方 根据大佬们的writeup,要修改三个地方: 1.扩展名filename 2.filename下面一行的Content-Type:image/jpeg 3.最最最重要的是请求头里的Co ...
- 偏移分页器、游标分页器、Django-filter插件
复习 """ 1.drf-jwt签发与校验源码 签发token的请求 - 登录请求 - ObtainJSONWebToken - post - 将账号密码丢给序列化类处理 ...
- 主席树 hdu 4417
求一个区间内小于等于limit的数: 主席树模板题. 求出每一个节点的sum: #include<cstdio> #include<algorithm> #include< ...
- A. DZY Loves Chessboard
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m columns. So ...
- hadoop学习笔记(五)hadoop伪分布式集群的搭建
本文原创,如需转载,请注明作者和原文链接 1.集群搭建的前期准备 见 搭建分布式hadoop环境的前期准备---需要检查的几个点 2.解压tar.gz包 [root@node01 ~]# ...
- php 基础 字符型转换整形
示例: 可以得出规律:以有效数字开头的,取有效数字.以非有效数字开头的都转换为0:
- MyBatis操作mysql数据库查询出来是时间戳的问题
在pojo类中用java.sql.Date接收就能正常显示
- android实现扫一扫等功能
链接:https://blog.csdn.net/weixin_40399313/article/details/78814325
- 树莓派实现SIM868 ppp拨号上网
环境:raspbian-stretch(2018-06-27) 树莓派:3代B型 SIM868模块具有GPRS数据传输功能(2G网络),但是模块是通过AT指令控制的,在树莓派上用AT指令控制会非常不方 ...