题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/F

题意:

     给你某星球一年的天数,问,一堆人中至少有两个人的生日在同一天的概率大于0.5,那堆人最少多少人。

     案例:

     input

     2

     365

     669

     output

     Case 1: 22

     Case 2: 30

思路分析:

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

      当ans小于等于0.5了就要停止循环。

源代码如下:

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int birthday(int n)
 5 {
 6     double ans=1;
 7     int s=0;
 8     while(ans>0.5)
 9     {
10         s++;
11         ans*=(double)(n-s)/n;
12     }
13     return s;
14 }
15 int main()
16 {
17     int T,n,t=0;
18     scanf("%d",&T);
19     while(T--)
20     {
21         scanf("%d",&n);
22         printf("Case %d: %d\n",++t,birthday(n));
23     }
24     return 0;
25 }

 

posted on 2015-08-21 19:18  尘埃。  阅读(330)  评论(0编辑  收藏  举报