Light OJ:1104 Birthday Paradox(数学概率+思维)

1104 - Birthday Paradox
Time Limit: 2 second(s)Memory Limit: 32 MB

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 23people 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

Output for Sample Input

2

365

669

Case 1: 22

Case 2: 30

 


PROBLEM SETTER: JANE ALAM JAN

题目大意:我过生日,问至少请来多少人,使得聚会上所有人(包括我自己)两两人生日相同的概率为0.5.

解题思路:以我为参考,比如一年365天,那么下一个人过生日与我不同的概率是364/365,再下一个人与前两个人生日不同的概率为363/365,。。。那么答案就出来了,当364/365*363/365*362/365*...等于0.5的时候就符合题意了,统计下人数。

代码如下:

#include <cstdio>
int main()
{
	int t;
	scanf("%d",&t);
	int k=1;
	while(t--)
	{
		double day;
		scanf("%lf",&day);
		double res=1.0;
		int ans=0;
		double ji=day-1.0;
		while(res>0.5)
		{
			res=(ji/day)*res;
			ji=ji-1.0;
			ans++;//人数+1 
		}
		printf("Case %d: ",k++);
		printf("%d\n",ans);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值