LightOJ 1104

    xiaoxiao2025-03-01  7

    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

    这一道题就是理解题目题意,数学思想,正方面复杂,用反方面,求的是至少2人同一天生日的概率,可知,反面就是全部都不在同一天,那么就是n/n*(n-1)/n......并且判断是否满足概率<0.5即可

    #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> using namespace std; #define N 1100 #define g 9.81 int main() {     int i, n, T, m, t=1;     scanf("%d", &T);     while(T--)     {         scanf("%d", &n);         double ans=1.0;         i=0, m=0;         while((1-ans)<0.5)         {             ans*=1.0*(n-i)/n;             i++;             m++;         }         printf("Case %d: %d\n", t++, m-1);     }     return 0; }

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