博客园 首页 私信博主 显示目录 隐藏目录 管理

Light OJ 1104 第六周F题

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=1;
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        int total=0;
        double p=1.0;
        for(int i=0; i<n; i++)
        {
            p*=double(n-i)/n;
            if(1-p>=0.5)
                break;
            total++;

        }
        printf("Case %d: %d\n",k++,total);
    }
    return 0;
}

 

posted @ 2015-08-19 15:06  hfcnal  阅读(154)  评论(0编辑  收藏  举报