Light OJ 1104 第六周F题

F - 概率(经典问题)

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

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

程序分析:给你某个星球上一年的天数,求出至少有两个人生日相同的种数,且要使这种情况发生的概率最小为0.5

至少有两个人的生日相同,对立面就是任何两人的生日都不相同,求出它的概率为p,然后只要使1-p>=0.5即可

#include<iostream>
#include<cstdio>
using namespace std;
int n,t,k=1;
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        int total=0;
        double p=1.0;
        for(int i=0; i<n; i++)
        {
            p*=double(n-i)/n;
            if(1-p>=0.5)
                break;
            total++;

        }
        printf("Case %d: %d\n",k++,total);
    }
    return 0;
}
时间: 2024-12-16 08:40:20

Light OJ 1104 第六周F题的相关文章

light oj 1104 Birthday Paradox (概率题)

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 b

程序设计入门—Java语言 第六周编程题 1 单词长度(4分)

第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这里的单词与语言无关,可以包括各种符号,比如"it's"算一个单词,长度为4.注意,行中可能出现连续的空格. 输入格式: 输入在一行中给出一行文本,以'.'结束,结尾的句号不能计算在最后一个单词的长度内. 输出格式: 在一行中输出这行文本对应的单词的长度,每个长度之间以空格隔开,行末没有最后

HDU 1465 第六周L题

Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情.如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题

福建工程学院寒假作业第一周F题

Subsequence TimeLimit:1000MS  MemoryLimit:65536K 64-bit integer IO format:%lld 问题描述: A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a progra

Light OJ 1104 Birthday Pardo(生日悖论)

ime Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu 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 in

概率 light oj 1104

t个数据 n天一年  至少2个人在同一天生日的概率>=0.5 问至少多少人 显然要从反面考虑 设365天 都在不同一天的概率 p(num)=1*364/365*363/365...; =(day***(day-num+1) )/(day)的num次: !p(num)=1-p(num); 而p(n)前一项和后一项更容易找规律 具体见代码 1 #include<stdio.h> 2 3 int main() 4 { 5 int t,ca; 6 scanf("%d",&am

第六周O题(等边三角形个数)

O - 计数 Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of it

HDU1465 第六周L题(错排组合数)

L - 计数,排列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然

第六周 N题

Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks. He wants to make a calculated risk, and grab as much money as possible. But his friends - Hermi