LightOJ1104---Birthday Paradox (概率)

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: [email protected]
    > 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;
}
时间: 2024-10-29 10:46:44

LightOJ1104---Birthday Paradox (概率)的相关文章

codeforces 711E. ZS and The Birthday Paradox 概率

已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可能非常大,对a,b分别%(10^6+3) 注意,这道题是先化到最简,再分别取模 首先,特判 k > 2^n 时,a = 1,b = 1 没有2个人同一天生日的概率为: 2^n * (2^n - 1) * ... * (2^n - k + 1) / 2^(nk) 所以a,b化简之前分别是: a = 2nk

Birthday Paradox lightoj 1104 生日悖论(概率)

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

light oj 1104 Birthday Paradox (概率题)

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 b

lightoj1104(数学概率与期望)

题意: 加入一年有n天; 那么至少有几个人,可以保证至少两个人同一天生日的概率大于等于0.5; 思路: 转化一下题意; 就是求所有人生日都不同的概率小于等于0.5(那么至少两个人同一天就是大于等于0,5); 加入一年365天.那么10个人全都不同天生日的概率就是 366/366 * 365/366 * 364/366 .... * 356/366; 就可以得到公式了; 所以我们累乘过去知道小于等于0.5;看累乘几个; #include<cstdio> #include<cstring&g

LightOj 1104 - Birthday Paradox(生日悖论概率)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1104 题意:一年365天,在有23个人的情况下,这23个人中有两个人生日相同的概率是大于 0.5 的: 现在在不同的星球上一年有n天,求出x,至少有 x 个人才能使得这 x 人中有两个人的生日相同的概率是>=0.5的:现在除了自己之外还要 x 个人,求x: 我们按 n = 365 算的话,那么有x个人,这些人生日都不相同的概率是 p = 1 * 364/365 * 363/365 *

LightOJ 1104 - Birthday Paradox【概率】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1104 题意:生日驳论,求最小满足条件的人数 代码: #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <bitset> #include <math.h> #include <cty

F - 概率(经典问题)

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

LightOJ 1104 Birthday Paradox

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

算生日相同的概率

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