LightOJ 1104 Birthday Paradox 概率
Birthday Paradox LightOJ - 1104
给定一年的天数 ,求至少需要多少人,才能保证其中至少有两个人的生日在同一天的概率 ?
从反面考虑,假如 个人每个人的生日都不相同,那么概率是:
代码如下:
#include<iostream>
#include<cstdio>
//#define WINE
using namespace std;
int T,iCase,n,res;
double p;
int main(){
#ifdef WINE
freopen("data.in","r",stdin);
#endif
scanf("%d",&T);
while(T--){
scanf("%d",&n);
res=1,p=1;
for(int i=n-1;i>=1;i--){
p=p*i/n;
if(p<=0.5)break;
res++;
}
printf("Case %d: %d\n",++iCase,res);
}
return 0;
}