集训第六周 E题
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题的更多相关文章
- 集训第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 集训第六周 M题
Description During the early stages of the Manhattan Project, the dangers of the new radioctive ma ...
- 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)
第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...
- hdu 4548 第六周H题(美素数)
第六周H题 - 数论,晒素数 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 集训第六周 古典概型 期望 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 ...
- 集训第六周 矩阵快速幂 K题
Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...
- 集训第六周 数学概念与方法 计数 排列 L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...
- 集训第六周 数学概念与方法 J题 数论,质因数分解
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...
- 集训第六周 数学概念与方法 数论 线性方程 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...
随机推荐
- 题解报告:poj 2823 Sliding Window(单调队列)
Description An array of size n ≤ 106 is given to you. There is a sliding window of size k which is m ...
- Activity的onSaveInstanceState和onRestoreInstanceState触发的时机
转自:http://www.cnblogs.com/heiguy/archive/2010/10/30/1865239.html 1.原文 先看Application Fundamentals上的一段 ...
- 使用mysql实现mybatis的分页效果
1.mybatis.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configur ...
- iOS捷径(Workflow 2.0)拓展
前言 iOS12 捷径(Workflow 2.0)入门 iOS12 捷径(Workflow 2.0)进阶 iOS12捷径(Workflow 2.0)实例大全 注:本文主要介绍如何获取URL Schem ...
- [BZOJ1025][SCOI2009]游戏 DP+置换群
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1025 题目中的排数就是多少次回到原来的序列.很显然对于题目所描述的任意一种对应法则,其中一 ...
- wordpress在撰写新文章界面的显示选项按钮点击无反应的解决办法
原文链接:wordpress在撰写新文章界面的显示选项按钮点击无反应的解决办法 最近升级wordpress之后,发现在文章编辑界面的添加新媒体和可视化按钮点击无反应,如下: 然后就在网上找解决办法, ...
- json两层解析
public class Demo { public static void main(String[] args) { try { // 创建连接 服务器的连接地址 URL url = new UR ...
- Android学习笔记(十一) Intent
一.Intent对象的基本概念 -Intent是Android应用程序组件之一 -Intent对象在Android系统当中表示一种意图 -Intent当中最重要的内容是action与data 二.In ...
- 阿里云ecs绑定域名
在阿里云服务器ECS一切配置ok后,通过域名一直访问不成功,结果发现还需要在后台进行安全组的规则设定:
- c++通过管道pipe获取cmd输出的字符
#include <stdio.h>#include<iostream>#include<string>using namespace std; // 描述:exe ...