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

求出要多人才能保证两个人生日在同一天的概率大于0.5.

 1 #include<cstdio>
 2 int main()
 3 {
 4     int t,k=0;
 5     scanf("%d",&t);
 6     while(t--)
 7     {
 8         double n,p=1;
 9         scanf("%lf",&n);
10         int i;
11         for(i=1;;i++)
12         {
13             p*=((n-i)/n);
14             if(p <= 0.5)
15                 break;
16         }
17         printf("Case %d: %d\n",++k,i);
18     }
时间: 2024-12-30 03:44:17

light oj 1104 Birthday Paradox (概率题)的相关文章

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 ar

概率 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

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 1030 - Discovering Gold(概率dp)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的地方, 每个格子中都有价值为v[i]的宝藏. 有一个6面的骰子,数字为从1-6, 每次摇一次骰子, 得到的数字x后, 你可以到达距离当前位置大x的位置, 并且得到那个位置的宝藏. 如果要走的位置在n的外面, 那么在此摇骰子, 直到找到一个合适的数字.到达n位置的时候结束. 现在想知道走到n位置的能够

Light OJ 1248 - Dice (III) 概率DP

n个面的骰子 求每个面至少扔到一次的期望值 设dp[i]为已经扔了i个不同面的期望值 dp[n] = 0 求dp[0] 因为dp[i]为还需要扔i个不同的面 每次可能扔中已经扔过的面或者没有扔到过的面2中情况 所以dp[i] = (i/n)*dp[i] + (n-i)/n*dp[i+1] +1 等号2边都有dp[i] 移项得dp[i] = dp[i+1]+n/(n-i) #include <cstdio> #include <cstring> #define imax 100005

Light OJ 1028 Trailing Zeroes (I) 求n因子数

今天真机调试的时候莫名其妙遇到了这样的一个问题: This product type must be built using a provisioning profile, however no provisioning profile matching both the identity "iPhone Developer" and the bundle identifier..... 具体如下图所示: 十分蛋疼, 发现不管是从网上下的demo, 还是自己的过程.凡事真机测试的时候都

[DP] Light Oj 1017 Brush(III)

题目为 light oj 1017. 现在是凌晨两点二十分,我却毫无睡意,这题折腾了我一个晚上,一直没有做对,最后发现转移方程忽略了一个重要的条件,泪奔-. 干脆不睡觉,写一篇题解警醒自己,也算是对于自己考虑问题智障的惩罚. 我真是个智障 0 s 0 ..... 题目大意是 , 给你N个二维坐标上的点 (x,y) , 每一个点代表一个污渍,现在有一把宽度为 W 的刷子,平行于 x 轴移动 K 次,问,最多能擦掉多少污渍. 很明显这题和x坐标一点关系都没有(因为刷子沿着平行x轴移动,并可以移动无限

Light OJ 1251 Forming the Council 2-SAT输出任意一组解

题目来源:Light OJ 1251 Forming the Council 题意:若干了条件至少满足一个 求是否有方案 输出任意一种可能的方案 留下的人的个数 思路:2-SAT基础题 #include <cstdio> #include <cstring> #include <vector> using namespace std; const int maxn = 100010; int n, m; vector <int> G[maxn*2]; boo

light oj 1007 Mathematically Hard (欧拉函数)

题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数,若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N / a) * a:若(N % a == 0 && (N / a) % a != 0) 则有:E(N) = E(N / a) * (a - 1) 对于这题来说,首先卡MLE..只能开一个数组..所以把前缀和也存到欧拉数组里.然后卡long long..要用unsigned long long .