zoukankan      html  css  js  c++  java
  • LightOJ-1104-birthday Paradox(概率)

    链接:

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

    题意:

    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.

    思路:

    考虑至少两个人生日同一天(Pa) = 1-所有人生日不同(Pb)
    即当(Pb)<=0.5时满足条件.Pb = 1(n-1)/n(n-2)/n...

    代码:

    #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
    ", ++cnt, res);
        }
    
        return 0;
    }
    
  • 相关阅读:
    Nginx报400 Bad Request
    当前系统代理不是安全代理,是否信任
    nginx反向代理解决跨域问题
    SQL Prompt快捷键
    本地SQL Server怎么连接服务器上的数据库
    进制之间的转换
    计算机知识汇总
    C#语言学习记录
    excel常用技巧
    T-SQL学习记录
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11450588.html
Copyright © 2011-2022 走看看