LightOJ1104---Birthday Paradox (概率)

来源:互联网 发布:c语言中指针有什么用 编辑:程序博客网 时间:2024/06/09 18:55

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

Output for Sample Input

2

365

669

Case 1: 22

Case 2: 30

Problem Setter: Jane Alam Jan

暴力算了下大概100000的时候要370多个人,鉴于人很少所以直接暴力算就行了

/*************************************************************************    > File Name: e.cpp    > Author: ALex    > Mail: zchao1995@gmail.com     > Created Time: 2015年04月30日 星期四 16时03分38秒 ************************************************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace std;const double pi = acos(-1.0);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;int main() {    int t;    int icase = 1;    scanf("%d", &t);    while (t--) {        int n;        double p;        scanf("%d", &n);        for (int i = 1; i <= 400; ++i) {            p = 1;            int cnt = n;            for (int j = 1; j <= i; ++j) {                p *= (cnt * 1.0 / n);                --cnt;            }            if (p <= 0.5) {                printf("Case %d: %d\n", icase++, i - 1);                break;            }        }    }    return 0;}
0 0