IME Limit:2000MS
Memory Limit:32768KB
64bit IO Format:%LLD &%llu
Description
Sometimes some mathematical results is hard to believe. One of the common problems is the birthday paradox. Suppose you is in a party where there is people including you. What's the probability that at least and the party has same birthday? Surprisingly the result is more than 0.5. Now this is the opposite. You are given the number of days in a year. Remember that's you can are in a different planet, for example, in Mars, and a year are 669 days long. You has to find the minimum number of people you has to invite in a party such that the probability of at least B peop The Le in the party has 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 plan Et.
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
Program Analysis: The main idea of the problem is that if there are 23 in a room, then at least two people have the same probability of birthdays of more than 50%, but if they are 669 in Mars a year, so that they more than 50% of the probability is 30 people, we have to do is to enter the number of days to calculate the probability of more than 50% people.
This topic uses the sort, so if the number of a large will be beneficial, I here this code is better considering this situation, is the side by side. The second point is that the beginning of my main function is the double type result is the CE finally changed to int type before.
Program code:
#include <iostream>#include<cstdio>using namespacestd;DoubleBirthdayintN) {Doubleans=1.0; intm=0; for(intI=0; ; i++) {ans*=(Double) (N-i)/N; M++; if(1.0-ans>=0.5) Break; } returnm;}intMain () {intt,m,j=0; CIN>>T; while(t--) {J++; CIN>>m; intK; K=birthday (m); printf ("Case %d:%d\n", j,k-1); } return 0;}
Light OJ 1104 Birthday Pardo (Birthday paradox)