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;
    }
    
  • 相关阅读:
    [C#1] 2类型基础
    [C#2] 5迭代器
    [C#1] 6方法
    [C#1] 8数组
    [C#1] 12特性
    [C#1] 10事件
    [C#2] 2匿名方法
    实用代码JavaScript实用小函数一枚(深入对象取值)
    [C#1] 11接口
    实用代码C#获取本机网络适配器信息及MAC地址
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11450588.html
Copyright © 2011-2022 走看看