集训第六周 数学概念与方法 概率 F题

Submit Status

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

 

每个人都有自己的生日,如果一群人站在一起,那么他们有至少两个人生日相同的概率是多少? 例如有任意22个人站在一起,概率就能达到0.5

所以问你给出一年的时间长(不一定是365天,有可能是火星来的),需要选出至少多少人才能使概率不低于0.5

 

方法:选N个人,这一群人生日都不相同的概率是P=364/365+363/365+362/365.........

最后使得P小于等于0.5就行了

 

#include"iostream"
#include"cstdio"
using namespace std;
int main()
{
    int T,ca=1;
    cin>>T;
    while(T--)
    {
        int year,sel;
        cin>>year;
        sel=year;
        int ans=0;
        double p=1.0;
        while(p>0.5)
        {
            ans++;
            sel--;
            p*=(sel*1.0)/year;
        }
        printf("Case %d: %d\n",ca++,ans);
    }
    return 0;
}
O(O_O)O

 

posted @ 2015-08-20 08:33  江南何采莲  阅读(190)  评论(0编辑  收藏  举报