E - 期望(经典问题)

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit Status

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 than10-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/(n-i)

#include<iostream>
#include<cstdio>
using namespace std; int main()
{
int i,j,T,ca=;
cin>>T;
while(T--)
{
int n;
cin>>n;
double ans=;
for(i=;i<=n-;i++)
ans+=n*1.0/(n-i);
printf("Case %d: %.10f\n",++ca,ans);
}
return ;
}

集训第六周 E题的更多相关文章

  1. 集训第六周 O题

    Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...

  2. 集训第六周 M题

    Description   During the early stages of the Manhattan Project, the dangers of the new radioctive ma ...

  3. 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)

    第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...

  4. hdu 4548 第六周H题(美素数)

    第六周H题 - 数论,晒素数 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   De ...

  5. 集训第六周 古典概型 期望 D题 Discovering Gold 期望

    Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...

  6. 集训第六周 矩阵快速幂 K题

    Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...

  7. 集训第六周 数学概念与方法 计数 排列 L题

    Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...

  8. 集训第六周 数学概念与方法 J题 数论,质因数分解

    Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...

  9. 集训第六周 数学概念与方法 数论 线性方程 I题

    Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...

随机推荐

  1. jQuery笔记之事件绑定

    .on(),off(),.one(),.trigger() .hover() jQuery实例方法-动画 .show(),.hide(),.toggle() 参数:null或(duration,eas ...

  2. 《Windows核心编程系列》十谈谈同步设备IO与异步设备IO之异步IO

    同步设备IO与异步设备IO之异步IO介绍 设备IO与cpu速度甚至是内存访问相比较都是比较慢的,而且更不可预测.虽然如此,通过使用异步设备IO我们仍然能够创造出更高效的程序. 同步IO时,发出IO请求 ...

  3. BFS(最短路) HDOJ 4308 Saving Princess claire_

    题目传送门 题意:一个(r*c<=5000)的迷宫,起点'Y‘,终点'C',陷阱‘#’,可行路‘*’(每走一个,*cost),传送门P,问Y到C的最短路 分析:一道最短路问题,加了传送门的功能, ...

  4. 输入一个秒数,要求转换为XX小时XX分XX秒的格式输出出来;

    package arithmetic; import java.util.Scanner; import org.junit.Test; public class Test02 { /** * 输入一 ...

  5. JDBC中Oracle的SID和ServiceName两种方式的连接字符串格式

    SID格式: jdbc:oracle:thin:@<host>:<port>:<SID> 如: jdbc:oracle:thin:@192.168.1.1:1521 ...

  6. Oracle中的序列

    序列是什么? 序列是用来生成唯一.连续的整数的数据库对象.序列通常用来自动生成主键或唯一键的值.序列可以按升序排列,也可以按照降序排列. 其实Oracle中的序列和MySQL中的自增长差不多一个意思. ...

  7. LN : leetcode 413 Arithmetic Slices

    lc 413 Arithmetic Slices 413 Arithmetic Slices A sequence of number is called arithmetic if it consi ...

  8. poj3662 Telephone Lines

    思路: 二分+最短路.最短路也可以用来计算从a到达b所需的边权不超过x的边的数量. 实现: #include <cstdio> #include <cmath> #includ ...

  9. http的请求与响应-----content-type

    content-type 指请求消息头的中请求消息数据的格式 有三种用法 第一种:设置在request header的参数中 js中可以在发送请求前在请求消息头中设置content-typevar x ...

  10. 用yunio网盘搭建git私有仓库

      研究生开始奔波于教研室和寝室之间,于是想搭建一个git私有仓库来管理自己在做的项目或者学习资料.一来可以很方便的管理项目,二来可以学习使用git.我的主要工作平台是Linux,这也是我选择yuni ...