LightOJ1104---Birthday Paradox
来源:互联网 发布:windows怎么升级版本 编辑:程序博客网 时间:2024/04/30 06:09
LightOJ1104---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 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减去,一直减下去直到小于0.5,剩下的自然是可能的概率大于0.5了,输出这个时候的n,别忘了减去自己。1的话特判输出1。
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<iostream>using namespace std;int main(){double n,day;int t,text = 1;scanf("%d",&t);while(t--){n = 0;scanf("%lf",&day);if(day == 1){printf("Case %d: 1\n",text++);continue;}n = 1;for(int i=1; i<day; i++){n = n*(day-i)/day;if(n<=0.5){printf("Case %d: %d\n",text++,i);break;}}}return 0;}
- LightOJ1104---Birthday Paradox (概率)
- LightOJ1104---Birthday Paradox (概率)
- LightOJ1104---Birthday Paradox
- LightOJ1104---Birthday Paradox (概率)
- LightOJ1104-Birthday Paradox
- LightOJ1104---Birthday Paradox(生日悖论(概率))
- birthday paradox
- Birthday Paradox
- Birthday Paradox
- lightoj 1104 Birthday Paradox
- LightOJ 1104 Birthday Paradox
- light OJ Birthday Paradox.
- 【LightOJ 1104 Birthday Paradox】
- LightOJ 1104Birthday Paradox
- Birthday Paradox ||生日悖论
- Birthday Paradox LightOJ
- lightoj-1104-Birthday Paradox
- 【LightOJ 1104】Birthday Paradox
- Optimization(最优化)
- LightOJ1104 birthday parado(经典概率)
- 简单工厂模式--简单的看法
- nodejs http调用报错:socket hang up
- 51nod-独木舟问题
- LightOJ1104---Birthday Paradox
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots dfs
- javaWeb---cookie
- Feature Selection(特征选择)
- 网络编程(2)UDP
- Linux(入门)
- python json模块使用示例
- Android AIDL问题
- 流媒体服务器搭建总结