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

 题意:
  有一个n面的骰子,每次投出,每个面出现的概率都一样
  问你每个面都出现一次的期望
题解:
  假设dp[i] 为还有i个面没有出现的期望
  那么答案是dp[n];
  那么有 
        dp[i] = (dp[i-1]*(i) + (n-i)*dp[i]) / n;
  化简一下即可
#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]);
}
}

最新文章

  1. 学习javascript数据结构(一)——栈和队列
  2. ListView控件
  3. 图概PHP生命周期
  4. SQL Server里的自旋锁介绍
  5. 72. Edit Distance
  6. insert into (select...WITH CHECK OPTION) values(...)
  7. Android 读取手机短信
  8. jsonp多次请求报错 not a function的解决方法
  9. MAC安裝《Genymotion Android模擬器》大玩Android APP (神魔之塔)
  10. Androidstudio2.0.0汉化教程及汉化包。
  11. 【epubcfi函数generateRangeFromCfi和generateCfiFromRange】两者的区别和适用性,以及另一种实现
  12. iWeb峰会(HTML5峰会)2015年7月19日上海站会后感想
  13. python 浅析IO 模型
  14. Delphi 2010 新增功能之: IOUtils 单元(6): TPath(结构体) 的方法与属性
  15. 谷歌pixel手机解BL锁、刷机、破解电信(史上最详细的帖子)
  16. FFmpeg 裁剪——音频解码
  17. redis 的 docker 镜像使用
  18. Vue组件中引入jQuery
  19. dos 批处理中%cd% 和%~dp0%的区别
  20. c#打印(转)

热门文章

  1. 统一软件开发过程(rup)理解
  2. Linux 下安装配置 JDK7
  3. [bug]The file ‘/xxx/xxx.aspx’ has not been pre-compiled, and cannot be requested
  4. 如何设置通过ip访问数据库
  5. ASP.NET MVC学习笔记-----ActionInvoker
  6. javascript模板插件amaze.js
  7. mySQL笔记1
  8. Third scrum meeting - 2015/10/28
  9. 利用LineRenderer画出一个圆,类似于lol中的攻击范围
  10. xcode arc引起的autorelease报错问题