## lightoj 1104 Birthday Paradox probability

N give you the number of days a year, not to ask yourself, how many people to invite at least, there is the probability of not less than 0.5, it was hit birthday.

Invite the maximum number of people, there is the probability of not more than 0.5, no one hit the birthday equivalent.

The first personal invitation, birthday hit probability is (n - 1) / n.

Invite a second person, birthday hit probability is (n - 1) / n * (n - 2) / n.

And so on can be calculated.

``` 1 #include <cstdio>
2 using namespace std;
3 double P;
4 int T,n,cas;
5 int main()
6 {
7     for (scanf("%d",&T);T != 0;T--)
8     {
9         cas++;
10         P = 1.0;
11         scanf("%d",&n);
12         for (int i = 1;;i++)
13         {
14             P *= (double)(n - i) / n;
15             if (P <= 0.5)
16             {
17                 printf("Case %d: %d\n",cas,i);
18                 break;
19             }
20         }
21     }
22     return 0;
23 }```

### Guess you like

Origin www.cnblogs.com/iat14/p/11410495.html
Recommended
Ranking
Daily