• 集训第六周 数学概念与方法 概率 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
  • 相关阅读:
    第一次个人编程作业
    第一次博客作业
    20175311 2018-2019-2 《Java程序设计》第五周学习总结
    2018-2019-2 20175311 实验一《Java开发环境的熟悉》实验报告
    20175311 2018-2019-2 《Java程序设计》第四周学习总结
    团队项目-选题报告
    第二次结队编程作业
    第一次结对编程作业
    第1组 团队展示(组长)
    第一次个人编程作业
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4744029.html
Copyright © 2020-2023  润新知