集训第六周 E题

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=0;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        double ans=0;
        for(i=0;i<=n-1;i++)
            ans+=n*1.0/(n-i);
        printf("Case %d: %.10f\n",++ca,ans);
    }
     return 0;
}

时间: 2024-10-30 13:06:28

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

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

第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这里的单词与语言无关,可以包括各种符号,比如"it's"算一个单词,长度为4.注意,行中可能出现连续的空格. 输入格式: 输入在一行中给出一行文本,以'.'结束,结尾的句号不能计算在最后一个单词的长度内. 输出格式: 在一行中输出这行文本对应的单词的长度,每个长度之间以空格隔开,行末没有最后

集训第六周 古典概型 期望 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 of the cave can contain any amount of gold. Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice a

集训第六周 数学概念与方法 概率 数论 最大公约数 G题

Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into

集训第六周 数学概念与方法 数论 筛素数 G题

Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.  给定一个区间,你能计算出这个区间内有多少个美素数吗? Input 第一行输入一个正整数T,表示总共有T组数据(T <= 10000). 接下来共T行,每行输入两个整数L,R(1<= L <= R <= 10

集训第六周 数学概念与方法 概率 F题

Submit Status Description Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there are 23 people including you. What is the probability that at least two peopl

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

Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情.如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不

集训第六周 数学概念与方法 概率 N题

N - 概率 Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks.

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

Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees are Shaking, Leaves are Falling. Lovers Walk passing, and so are You. ................................Write in English class by yifenfei Gir

集训第五周D题 LCS

Description In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countries (maybe except for Luxembourg). To enforce that Germa