相同的 birthday
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
题意:地球上一年是365天,在一个最聚会上,加上你自己有23个人.... 在这23个人中,有两个生日是同一天的概率超过50%。
现在要求你输入一年的天数,求在聚会上你还要邀请多少人,才可以使,有两个人生日是同一天的概率超过50%..
例如,火星上一年是669天,那么他还要邀请30个人才使得概率超过50%
解题思路:既然是求两个人同一天的生日的概率,那么就是1-P(E)。这里的P(E)表示任何两个人的生日都不相同的概率
1-P(E)=1-(n/n) * (n-1)/n * (n-2)/n *......... * (n-(m-1))/n
这里的m表示m个人.....
代码如下 :
#include <stdio.h>
double birthday(int n)
{
double ans=1.0;
int m=;
for(int i=; ; i++)
{
ans*=(double)(n-i)/n;
m++;
if(1.0-ans>=0.5)
break;
}
return m;
}
int main()
{
int T,N=;
scanf("%d",&T);
while(T--)
{
N++;
int n;
scanf("%d",&n);
int ans=birthday(n);
printf("Case %d: %d\n",N,ans-);
}
return ;
}
随机推荐
- vb.net详解MDI窗体操作方法
MDI窗体可以避免打开窗体的时候被无数个子窗体困扰,我将为大家一一的介绍一下vb.net中MDI窗体的操作方法 一.如何创建MDI窗体? 1.创建mdi主窗体 新建建立一个默认空白的Windows应用 ...
- POJ 3660 Cow Contest (闭包传递)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7690 Accepted: 4288 Descr ...
- Simofox 2.7 - 基于 pcxFirefox 定制(停更)
••• 现已停止更新,无良作者转战 Google Chrome ••• 项目名称:Simofox (Simple + Cool + Firefox) 项目介绍:Simofox 中译名西蒙狐,目前项目版 ...
- 转:自建CDN防御DDoS(1, 2, 3)infoq
本文中提到的要点: 1. 针对恶意流的应对方法与策略.(基本上,中级的,顶级的) 2. IP分类的脚本 3. 前端proxy工具的选择与使用. 4. 开源日志系统的选择与比较. (http:/ ...
- C#之ArrayList
using System.Collections; 新建: ArrayList list = new ArrayList(); 添加元素: int a = 1; list.Add(a); 遍历: fo ...
- 【ANT】Ant常用的内置task
ant 例如: <target name="callProjectB"> <echo message="In projectA calling proj ...
- ado模版不会自动生成
从数据库中更新模版的时候,其他文件都更新了,只有tt文件下的cs文件是没有更新的,没有添加也没有修改,在网上找了很久都没有这方面的信息. 其实只要删掉,重建一个ado模版就好.根本就不需要纠结.最后还 ...
- Part 93 Protecting shared resources from concurrent access in multithreading
- 运用DataTable进行行转列操作
public DataTable GetReverseTable(DataTable p_Table) { DataTable _Table = new DataTable(); ; i != p_T ...
- (转)Android之自定义适配器
ListView作为一个实际开发中使用率非常高的视图,一般的系统自带的适配器都无法满足开发中的需求,这时候就需要开发人员来自定义适配器使得ListView能够有一个不错的显示效果. 有这样一个Demo ...