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面的骰子,要你求,这个骰子每面出现一次的期望....

题解:第i面的骰子的期望就是n/i

代码如下:

 #include <stdio.h>
int main()
{
int T,N=;
scanf("%d",&T);
while(T--)
{
N++;
double n;
scanf("%lf",&n);
double ans=;
for(double i=1.0;i<=n;i++)
ans+=n/i;
printf("Case %d: %.10lf\n",N,ans);
}
return ;
}

第六周 E题 期望.....的更多相关文章

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

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

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

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

  3. light oj 1248 第六周E题(期望)

    E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Descri ...

  4. Codeforces 559A 第六周 O题

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

  5. 集训第六周 E题

    E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

  6. 第六周 N题

    Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...

  7. HDU 1465 第六周L题

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

  8. HDU 1405 第六周 J题

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

  9. HDU 2669 第六周 I题

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

随机推荐

  1. 《MFC游戏开发》笔记五 定时器和简单动画

    本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9332377 作者:七十一雾央 新浪微博:http:// ...

  2. oracle使用pfile或者spfile启动

    oracle 11G使用pfile启动数据库 startup pfile='pfile参数文件路径' oracle 11G使用spfile启动数据库 spfile=Windows缺省目录    %OR ...

  3. ionic使用sass

    sass 是一个css的预编译器,常见的预编译器有less,sass,stylus等,目前sass似乎更受青睐一些,bootstrap的最新版本以及ionic 都是用sass来构建页面效果的.这篇文章 ...

  4. javascript跨域请求RESTful Web Service

    跨域请求RESTful Web Service 当我们用js请求RESTful Web Service的时候,通常会出现跨域无法访问的问题,也就是无法正常得到我们要的值.jsonp是个解决问题的方法. ...

  5. 用xcode6.3编译早期工程时出现Undefined symbols for architecture x86_64错误的解决办法(转)

    Xcode升级到5.1 新特性之一就是默认让所有App都通过64位编译器编译.原来在Xcode5.0.x的时候默认的Standard architectures只有(arm7,armv7s),到5.1 ...

  6. 访问iPhone通讯录的问题

    每个APP只显示一次上图的提示,即使卸载APP也不显示.如果想再次显示提示,可进入 设置-->通用-->还原-->还原位置与隐私,即可. 而且在ios6中文环境下,访问通讯录会出现错 ...

  7. 关于inodes占用100%的问题及解决方法

    #df shows no file systems processedPosted by John Quaglieri on 27 July 2012 07:26 AMA df -m command ...

  8. EntityFramework使用中的一些Bug

    1. No Entity Framework provider found for the ADO.NET provider 解决方法:添加  EntityFramework.SqlServer.dl ...

  9. sqlserver跟踪

    本文以实际应用为目的,不在理论方面深究 1.打开跟踪器 或 2.新建跟踪-事件选择-列筛选器,HostName默认不显示,需勾选“显示所有列”,如果希望只跟踪某一客户端,可按下面的设置HostName ...

  10. 兼容性调试-- 在谷歌浏览器中,td 设置colspan的失效的问题

    通过设置table width="100%"table-layout="fixed" 解决