LightOJ 1248 Dice (III)
来源:互联网 发布:一彩软件 编辑:程序博客网 时间:2024/05/01 22:23
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26958
题意:有一个n面的骰子,每次投掷每个面都是等概率出现,求所有面都出现的期望投掷次数。
思路:f[i]表示已经出现了i个面,还需要投掷的期望次数,f[n] = 0 , f[i] = i/n * f[i] + ( n - i ) / n * f[i+1] + 1 , 化简后f[i] = f[i+1] + n / ( n - i ) , 所以答案就是∑n/i 1<=i<=n。
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdlib>#include <iostream>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <sstream>#include <queue>#include <utility>using namespace std;#define rep(i,j,k) for (int i=j;i<=k;i++)#define Rrep(i,j,k) for (int i=j;i>=k;i--)#define Clean(x,y) memset(x,y,sizeof(x))#define LL long long#define ULL unsigned long long#define inf 0x7fffffff#define mod %100000007int T;int n;int k = 0;void solve(){ double ans = 0; rep(i,1,n) ans+=(double)n/i; printf("Case %d: %0.9f\n",++k,ans);}int main(){ cin>>T; while(T--) { scanf("%d",&n); solve(); } return 0;}
0 0
- LightOJ 1248 Dice (III)
- lightoj 1248 Dice (III)
- LightOJ 1248 Dice (III)
- LightOJ 1248Dice (III)
- LightOJ 1248 Dice (III) [期望]
- LightOJ - 1248 Dice (III) 期望 + dp
- lightOJ 1248 - Dice (III) 概率DP
- lightoj 1248 Dice (III)(几何分布+期望)
- lightOj 1248 Dice (III) 概率公式
- 【LightOJ 1248】Dice (III)(概率DP)
- LightOJ-1248-Dice (III) (数学期望)
- Dice (III) LightOJ
- Dice (III) LightOJ
- Light OJ 1248 - Dice (III) 概率DP
- light oj 1248 - Dice (III)(期望)
- Dice (I) lightOJ 1145
- 1145 - Dice (I) Lightoj
- LightOJ 1193 Dice (II)
- spring boot 学习笔记(001) 新建Eclipse工程
- java的4中对象引用方式
- 下载Windows Embedded CE R2
- Android Gson生成、解析json数据
- 练习四1001畅通工程
- LightOJ 1248 Dice (III)
- NGUI中2DSprite在苹果系统上显示出错的问题解决
- 由于ndk引发的几个bug,以及解决方法
- android 运行项目闪退
- 自顶向下分治实现的归并算法
- MyBatis Generator 配置
- Nginx之页面缓存
- NSURLSession的GET和POST请求的封装
- 糗事百科交互式爬虫