LightOJ 1104 Birthday Paradox

一年有n天,至少有几个人,可以保证至少两个人同一天生日的概率大于等于0.5;

反面思考,就是全都不等的概率小于0.5。

#include <iostream>
#include <functional>
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

int main()
{
    int T,ncas=1;
    scanf ("%d",&T);
    while (T--)
    {
        int n;
        scanf ("%d",&n);
        double p=1,now=(double)n;
        while (now)
        {
            p*=now/n;
            if (p<=0.5)
                break;
            now--;
        }
        printf ("Case %d: %d\n",ncas++,n-(int)(now+0.5));
    }
    return 0;
}

posted on 2016-04-28 15:33  very_czy  阅读(152)  评论(0编辑  收藏  举报

导航