• 集训第六周 数学概念与方法 概率 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
  • 相关阅读:
    结语
    创建ejs模板的express工程
    浏览器控制台命令调试——console
    JS获取URL中参数值(QueryString)的4种方法分享
    oracle之报错:ORA-00054: 资源正忙,要求指定 NOWAIT
    javascript 获取页面的高度及滚动条的位置的代码
    javascript 页面各种高度宽度
    导出Excel之Epplus使用教程2(样式设置)
    索引 'GXHRCS.PK_A253' 或这类索引的分区处于不可用状态
    数据库操作
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4744029.html
Copyright © 2020-2023  润新知