LightOJ 1248 Dice (III) 概率
Description
Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the dice is fair, that means when you throw the dice, the probability of occurring any face is equal.
For example, for a fair two sided coin, the result is 3. Because when you first throw the coin, you will definitely see a new face. If you throw the coin again, the chance of getting the opposite side is 0.5, and the chance of getting the same side is 0.5. So, the result is
1 + (1 + 0.5 * (1 + 0.5 * ...))
= 2 + 0.5 + 0.52 + 0.53 + ...
= 2 + 1 = 3
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n ≤ 105).
Output
For each case, print the case number and the expected number of times you have to throw the dice to see all its faces at least once. Errors less than 10-6 will be ignored.
Sample Input
5
1
2
3
6
100
Sample Output
Case 1: 1
Case 2: 3
Case 3: 5.5
Case 4: 14.7
Case 5: 518.7377517640
#include <cstdio>
#include <cstring>
#include <vector>
#include<iostream>
#include <algorithm>
using namespace std;
const int N = 1e2 + , M = 1e5+ , mod = 1e9 + , inf = 2e9;
int T,n,x;
double dp[M+],f,p;
int main()
{
int cas = ;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
dp[] = 0.0;
for(int i=;i<=n;i++) {
dp[i] = (n + dp[i-]*i) / (double)(i);
}
printf("Case %d: %.6f\n",cas++,dp[n]);
}
}
最新文章
- 学习javascript数据结构(一)——栈和队列
- ListView控件
- 图概PHP生命周期
- SQL Server里的自旋锁介绍
- 72. Edit Distance
- insert into (select...WITH CHECK OPTION) values(...)
- Android 读取手机短信
- jsonp多次请求报错 not a function的解决方法
- MAC安裝《Genymotion Android模擬器》大玩Android APP (神魔之塔)
- Androidstudio2.0.0汉化教程及汉化包。
- 【epubcfi函数generateRangeFromCfi和generateCfiFromRange】两者的区别和适用性,以及另一种实现
- iWeb峰会(HTML5峰会)2015年7月19日上海站会后感想
- python 浅析IO 模型
- Delphi 2010 新增功能之: IOUtils 单元(6): TPath(结构体) 的方法与属性
- 谷歌pixel手机解BL锁、刷机、破解电信(史上最详细的帖子)
- FFmpeg 裁剪——音频解码
- redis 的 docker 镜像使用
- Vue组件中引入jQuery
- dos 批处理中%cd% 和%~dp0%的区别
- c#打印(转)
热门文章
- 统一软件开发过程(rup)理解
- Linux 下安装配置 JDK7
- [bug]The file ‘/xxx/xxx.aspx’ has not been pre-compiled, and cannot be requested
- 如何设置通过ip访问数据库
- ASP.NET MVC学习笔记-----ActionInvoker
- javascript模板插件amaze.js
- mySQL笔记1
- Third scrum meeting - 2015/10/28
- 利用LineRenderer画出一个圆,类似于lol中的攻击范围
- xcode arc引起的autorelease报错问题