E - 期望(经典问题)

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

 

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个面的骰子 求每个面至少扔到一次的期望值

比如给你6个面的 他的期望就是6*1+6*(1/2)+6*(1/3)+6*(1/4)+6*(1/5)+6*(1/6)

注意输出格式,小数点后十位。

#include<iostream>
#include<cstdio>
using namespace std;
int n,t,k=;
double dp[];
int main()
{
cin>>t;
while(t--)
{
cin>>n;
dp[n]=;
for(int i=n-;i>=;i--)
dp[i]=dp[i+]+(double)n/(i+);
printf("Case %d: %.10lf\n",k++,dp[]);
}
return ;
}

light oj 1248 第六周E题(期望)的更多相关文章

  1. Light OJ 1104 第六周F题

    F - 概率(经典问题) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Descri ...

  2. 第六周 E题 期望.....

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

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

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

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

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

  5. Codeforces 559A 第六周 O题

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

  6. 概率 light oj 1248

    t组样例 n<100010 dp[i]  从i翻到n面的期望 接下来翻 可能是i面已经有的 也可能是n-i面没有的 dp[i]=i/n*(dp[i]+1)+(n-i)/n*(dp[i+1]+1) ...

  7. 第六周 N题

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

  8. HDU 1465 第六周L题

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

  9. HDU 1405 第六周 J题

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

随机推荐

  1. keil中for循环变量递减,无法跳出循环的问题

    定义j时应注意其变量类型char,此循环当j=0时,再执行一次则keil中j=0XFF,而不是-1,所以无法跳出循环.但在vc6.0中是可以跳出循环的. 解决办法如下:不能让j的值为负数 uchar ...

  2. Python中 os._exit() sys.exit() exit()区别

    Python退出程序的方式有两种:os._exit(), sys.exit() 1)os._exit() 直接退出 Python程序,其后的代码也不会继续执行. 2)sys.exit() 引发一个 S ...

  3. Android RelativeLayout 布局android:layout_centerHorizontal="true"注意

    特别注意,如果要是 android:layout_alignTop="@id/bind_decode_item_layout" android:layout_centerHoriz ...

  4. Java串口通信具体解释

    序言 说到开源,恐怕非常少有人不挑大指称赞.学生通过开源码学到了知识,程序猿通过开源类库获得了别人的成功经验及可以按时完毕手头的project,商家通过开源软件赚到了钱……,总之是皆大欢喜.然而开源软 ...

  5. iOS中sqlite3操作

    声明:下面命令我没有所有使用过, 仅用于收藏, 欢迎大家指出当中的错误 'SELECT  count(*)   FROM sqlite_master WHERE type="table&qu ...

  6. 如何设置jsp默认的编码为utf-8

    方法一: 文件里写: <%@ page contentType="text/html; charset=UTF-8"  %> 方法二: 选择window –> P ...

  7. Android(java)学习笔记215:多线程断点下载的原理(JavaSE实现)

    1. 为什么需要多线程下载?     服务器的资源有限,同时的平均地分配给每个客户端.开启的线程越多抢占的服务的资源就越多,下载的速度就越块. 2. 下载速度的限制条件? (1)你的电脑手机宽带的带宽 ...

  8. 化繁为简,无需后端。巧用Yql+rss,搭建我的个人网站

    [本文含有大量的心理描写,没耐心的看官直接跳转到末尾即可] 前言: 最近做好了个人网站.很多人都喜欢用WordPress弄一个自己的博客之类的,但其实我觉得没这个必要,Lofter的功能.界面神马的于 ...

  9. Android中实现跨app之间数据的暴露与接收

    例如一个小项目:实现单词本的添加单词等功能 功能:不同的方式实现跨app之间数据的暴露与接收 暴露端app:实现单词的添加(Word.Translate),增删改查: 接收端app:模糊查询,得到暴露 ...

  10. discuz! X3 门户文章添加字段

    1. 首先需要去数据表里[llgp_portal_article_title]手动添加需要添加的字段. (注意: 数据表前缀依据自己的设置而定) 2. 修改模版template\default\por ...