Light OJ 1104 第六周F题
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
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 people in the party have same birthday? Surprisingly the result is more than 0.5. Now here you have to do the opposite. You have given the number of days in a year. Remember that you can be in a different planet, for example, in Mars, a year is 669 days long. You have to find the minimum number of people you have to invite in a party such that the probability of at least two people in the party have same birthday is at least 0.5.
Input
Input starts with an integer T (≤ 20000), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 105) in a single line, denoting the number of days in a year in the planet.
Output
For each case, print the case number and the desired result.
Sample Input
2
365
669
Sample Output
Case 1: 22
Case 2: 30
程序分析:给你某个星球上一年的天数,求出至少有两个人生日相同的种数,且要使这种情况发生的概率最小为0.5
至少有两个人的生日相同,对立面就是任何两人的生日都不相同,求出它的概率为p,然后只要使1-p>=0.5即可
#include<iostream>
#include<cstdio>
using namespace std;
int n,t,k=;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
int total=;
double p=1.0;
for(int i=; i<n; i++)
{
p*=double(n-i)/n;
if(-p>=0.5)
break;
total++; }
printf("Case %d: %d\n",k++,total);
}
return ;
}
Light OJ 1104 第六周F题的更多相关文章
- light oj 1248 第六周E题(期望)
E - 期望(经典问题) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...
- light oj 1104 Birthday Paradox (概率题)
Sometimes some mathematical results are hard to believe. One of the common problems is the birthday ...
- hdu 4548 第六周H题(美素数)
第六周H题 - 数论,晒素数 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)
第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...
- Codeforces 559A 第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- HDU 1465 第六周L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. ...
- Light OJ 1104 Birthday Pardo(生日悖论)
ime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Description Sometime ...
- 福建工程学院寒假作业第一周F题
Subsequence TimeLimit:1000MS MemoryLimit:65536K 64-bit integer IO format:%lld 问题描述: A sequence of ...
- 概率 light oj 1104
t个数据 n天一年 至少2个人在同一天生日的概率>=0.5 问至少多少人 显然要从反面考虑 设365天 都在不同一天的概率 p(num)=1*364/365*363/365...; =(day ...
随机推荐
- 2012蓝桥杯本科组C/C++决赛题
星期几 [结果填空] (满分5分) 1949年的国庆节(10月1日)是星期六. 今年()的国庆节是星期一. 那么,从建国到现在,有几次国庆节正好是星期日呢? 只要答案,不限手段! 可以用windows ...
- ArrayList 、Vector、 LinkList
public class TestList { public static void init(List list) { if(list!=null) ...
- HDU1510 White rectangles
White Rectangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 6th day
时光荏苒,岁月如梭,2016年马上就要过去了,今天PHP的核心知识基本上已经讲完,后面就要开始学习数据库,做项目之类的,心情还真是有点小激动.总之,新年新气象,祝愿各位在新的一年里能够心想事成,好好学 ...
- struts2原理架构图
struts2 原理架构图
- DateGridew导出Excel表+常见错误提示
在敲机房收费系统的时候,显示数据的时候需要将DateGridew 中的数据导出进Excel表.DateGridew导出Excel表是比较常见的,当然导出Excel表有很多种方法,下面是个人认为比较容易 ...
- 诡异的TNS-12541:TNS:nolistener
诡异的TNS-12541:TNS:nolistener OS:Microsoft Windows 2003 Ent ...
- [转] 深度解剖DIV+CSS工作原理
本文和大家重点讨论一下DIV+CSS工作原理,在一般情况的DIV+CSS开发静态html网页时,我们把html和CSS是分开的,形成html页面和CSS文件. DIV+CSS原理解剖 在一般情况的DI ...
- Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理
一.传统的磁盘管理 其实在Linux操作系统中,我们的磁盘管理机制和windows上的差不多,绝大多数都是使用MBR(Master Boot Recorder)都是通过先对一个硬盘进行分区,然后再将该 ...
- Python多进程使用
[Python之旅]第六篇(六):Python多进程使用 香飘叶子 2016-05-10 10:57:50 浏览190 评论0 python 多进程 多进程通信 摘要: 关于进程与线程的对比, ...