zoukankan      html  css  js  c++  java
  • 集训第六周 数学概念与方法 概率 F题

    Submit Status

    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 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

    2

    365

    669

    Sample Output

    Case 1: 22

    Case 2: 30

    每个人都有自己的生日,如果一群人站在一起,那么他们有至少两个人生日相同的概率是多少? 例如有任意22个人站在一起,概率就能达到0.5

    所以问你给出一年的时间长(不一定是365天,有可能是火星来的),需要选出至少多少人才能使概率不低于0.5

    方法:选N个人,这一群人生日都不相同的概率是P=364/365+363/365+362/365.........

    最后使得P小于等于0.5就行了

    #include"iostream"
    #include"cstdio"
    using namespace std;
    int main()
    {
        int T,ca=1;
        cin>>T;
        while(T--)
        {
            int year,sel;
            cin>>year;
            sel=year;
            int ans=0;
            double p=1.0;
            while(p>0.5)
            {
                ans++;
                sel--;
                p*=(sel*1.0)/year;
            }
            printf("Case %d: %d
    ",ca++,ans);
        }
        return 0;
    }
    O(O_O)O
  • 相关阅读:
    System.arraycopy()的用法?
    Java当中“+=”和“=+”的区别
    jsp FN 标签库的使用方法
    手作编辑画面处理
    mpfu 位编辑处理?
    5/14 自动跟新 位数编集 百分号添加 手作部品。
    jsp 4-14 知识总结
    jstl split 分割字符串?
    aws vpc 知识总结(助理级)
    典型的软件自动化测试框架
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4744029.html
Copyright © 2011-2022 走看看