light oj 1248 第六周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题(期望)的更多相关文章
- Light OJ 1104 第六周F题
		
F - 概率(经典问题) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...
 - 第六周 E题  期望.....
		
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
 - 程序设计入门—Java语言 第六周编程题 1  单词长度(4分)
		
第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...
 - hdu 4548   第六周H题(美素数)
		
第六周H题 - 数论,晒素数 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
 - Codeforces 559A   第六周  O题
		
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
 - 概率 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) ...
 - 第六周  N题
		
Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...
 - HDU  1465  第六周L题
		
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. ...
 - HDU  1405    第六周   J题
		
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all ...
 
随机推荐
- bzoj 2324 [ZJOI2011]营救皮卡丘(floyd,费用流)
			
2324: [ZJOI2011]营救皮卡丘 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1777 Solved: 712[Submit][Stat ...
 - [经典] 在未排序数组中返回topK大的数
			
解法一,排序 先从大到小快排,然后扫前K个返回 时间复杂度:O(NlogN),空间复杂度O(1) 解法二,优先队列 前K个放入优先队列中,与最小堆顶元素比较大小,若大于则删除堆顶并插入:否则跳过 时间 ...
 - 区别assign VS weak,__block VS __weak
			
在objective-c中,类中的全局变量经常使用如下的方式申明. @property(nonatomic(1),strong(2))UIImageView *imageView; 其中的1,2处是对 ...
 - Android注解利器:ButterKnife 的基本使用
			
前言 ButterKnife 简介 ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及setOnClickListener代码,可视化一 ...
 - mysql数据类型介绍
			
一.int.bigint.smallint 和 tinyint的区别详细介绍 bigint 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854 ...
 - SimpleDateFormat线程不安全问题处理
			
在工作中,通过SimpleDateFormat将字符串类型转为日期类型时,发现有时返回的日期类型出错,调用方法如下: public final class DateUtil { static fina ...
 - IOT数据库选型——NOSQL,MemSQL,cassandra,Riak或者OpenTSDB,InfluxDB
			
IoT databases should be as flexible as required by the application. NoSQLdatabases -- especially key ...
 - JQuery请求WebService返回数据的几种处理方式
			
打开自己的博客仔细浏览了一番,发现已经好久没有写博客了,由于最近一直比较忙碌懈怠了好多.默默反省三分钟.......言归正传,现在就对最近在学习webservice的过程中遇到的几种类型的问题中我的理 ...
 - java自定义对话框
			
package com.matp.view; import java.awt.FlowLayout; public class SimpleDialog extends JDialog impleme ...
 - 《Android开发艺术探索》读书笔记 (3) 第3章 View的事件体系
			
本节和<Android群英传>中的第五章Scroll分析有关系,建议先阅读该章的总结 第3章 View的事件体系 3.1 View基本知识 (1)view的层次结构:ViewGroup也是 ...