Light OJ:1104 Birthday Paradox(数学概率+思维)

    xiaoxiao2025-06-17  5

    1104 - Birthday Paradox    PDF (English)StatisticsForum Time Limit: 2 second(s)Memory Limit: 32 MB

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

    Output for Sample Input

    2

    365

    669

    Case 1: 22

    Case 2: 30

     


    PROBLEM SETTER: JANE ALAM JAN

    题目大意:我过生日,问至少请来多少人,使得聚会上所有人(包括我自己)两两人生日相同的概率为0.5.

    解题思路:以我为参考,比如一年365天,那么下一个人过生日与我不同的概率是364/365,再下一个人与前两个人生日不同的概率为363/365,。。。那么答案就出来了,当364/365*363/365*362/365*...等于0.5的时候就符合题意了,统计下人数。

    代码如下:

    #include <cstdio> int main() { int t; scanf("%d",&t); int k=1; while(t--) { double day; scanf("%lf",&day); double res=1.0; int ans=0; double ji=day-1.0; while(res>0.5) { res=(ji/day)*res; ji=ji-1.0; ans++;//人数+1 } printf("Case %d: ",k++); printf("%d\n",ans); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1300029.html
    最新回复(0)