Birthday Paradox LightOJ - 1104

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

题解:好像暴力都能过。。。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 const int maxn=1e5+5;
 5
 6 int kase,n,ans;
 7 double dp[maxn];
 8
 9 int main()
10 {   cin>>kase;
11     for(int t=1;t<=kase;t++){
12         cin>>n;     //用scanf("%d",&n)能少900多毫秒。。。。
13         double temp=1.0;
14         for(int i=1;i<=n;i++){
15             temp*=(n-i)*1.0/n;
16             if(temp<=0.5){ ans=i; break; }
17         }
18         printf("Case %d: %d\n",t,ans);
19     }
20     return 0;
21 } 
时间: 2024-08-07 14:59:34

Birthday Paradox LightOJ - 1104的相关文章

Birthday Paradox lightoj 1104 生日悖论(概率)

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

LightOj 1104 - Birthday Paradox(生日悖论概率)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1104 题意:一年365天,在有23个人的情况下,这23个人中有两个人生日相同的概率是大于 0.5 的: 现在在不同的星球上一年有n天,求出x,至少有 x 个人才能使得这 x 人中有两个人的生日相同的概率是>=0.5的:现在除了自己之外还要 x 个人,求x: 我们按 n = 365 算的话,那么有x个人,这些人生日都不相同的概率是 p = 1 * 364/365 * 363/365 *

LightOJ 1104 - Birthday Paradox【概率】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1104 题意:生日驳论,求最小满足条件的人数 代码: #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <bitset> #include <math.h> #include <cty

LightOJ 1104 Birthday Paradox

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

LightOJ 1104

题意: 给你一年有n天,求至少有m人使得至少有两个人在同一天生日的概率不少于0.5. 分析: 任意两个人不在同一天生日的概率为C(n,m)*m!/n^m,它的对立事件A为至少有两个人在同一天生日,则P(A) = 1 - C(n,m)*m!/n^m = 1 - P(n,m)/n^m(后一个P表示排列); 根据题意有P(A) >= 0.5 即 P(n, m)/n^m <= 0.5. 该式的展开式为 p = n/n*(n-1)/n*(n-2)/n*...*(n-m+1)/n, 因此只要判断该式的累乘

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

LightOJ 1030 Discovering Gold【概率】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题意:基础概率题. 代码: #include <stdio.h> #include <string.h> #include <vector> #include <string> #include <algorithm> #include <iostream> #include <iterator>

LightOJ - 1370 Bi-shoe and Phi-shoe

题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题目大意:给N个数a[i], N <= 1e6,问使 Φ(x) >= a[i] 成立的最小x的所有x的和是多少. 解题思路:我们知道的是对于素数 m 来说,phi[m] = m - 1.另一方面,对于一个合数 m 来说, phi[m] < phi[x] , x > m && x 是素数. 因此,我们可以认为,每

lightoj 1057 - Collecting Gold(状压dp)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1057 题解:看似有点下记忆话搜索但是由于他是能走8个方向的也就是说两点的距离其实就是最大的x轴或y轴的差.然后只有15个藏金点状压一下加dfs就行了. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #define inf 0X3f3f3f