LightOJ-1104-birthday Paradox (probability)

link:

https://vjudge.net/problem/LightOJ-1104

Meaning of the questions:

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.

Ideas:

Considering the at least two birthdays on the same day (Pa) = 1- all different birthday (Pb)
that is, when (Pb) <= 0.5 is satisfied condition. 1 = .pb (. 1-n-) / n- (-n-2) / n-. ..

Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;

int n;

int main()
{
    int t, cnt = 0;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &n);
        double p = 1;
        int sum = n;
        int res = 0;
        while (p > 0.5)
        {
            sum--;
            p = p*sum/n;
            res++;
        }
        printf("Case %d: %d\n", ++cnt, res);
    }

    return 0;
}

Guess you like

Origin www.cnblogs.com/YDDDD/p/11450588.html