【Light OJ 1104】Birthday Paradox
来源:互联网 发布:制版软件 编辑:程序博客网 时间:2024/06/08 03:46
题目连接:点击打开链接
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
题意:找出最少N个人,满足N个人中生日在同一天的概率大于等于0.5
题解:要计算至少两个人的生日同天概率可以逆着算所有人不同天生日的概率小于0.5,那么人数就是x = 1 * (n - 1)/n * (n-2)/n * … 直到x是小于0.5的。
#include<cstdio>int n;int main(){int t,cas;while(scanf("%d",&t)!=EOF){for(int i=0;i<t;i++){scanf("%d",&n);double k=1.0;cas=0;while(k>0.5){cas++;k*=(n-cas)*1.0/n;}printf("Case %d: %d\n",i+1,cas);}}return 0;}
- 【Light OJ 1104】Birthday Paradox
- light OJ Birthday Paradox.
- [概率+水] light oj 1104 Birthday Paradox
- LIGHT OJ-1104 Birthday Paradox 【组合】
- Light oj 1104 Birthday Paradox (生日悖论----概率)
- Light OJ:1104 Birthday Paradox(数学概率+思维)
- 【light-oj】-1104 - Birthday Paradox(数学,概率)
- Light oj 1104 Birthday Paradox 生日悖论-雀巢原理
- E - Birthday Paradox Light 1104
- lightoj 1104 Birthday Paradox
- LightOJ 1104 Birthday Paradox
- 【LightOJ 1104 Birthday Paradox】
- LightOJ 1104Birthday Paradox
- lightoj-1104-Birthday Paradox
- 【LightOJ 1104】Birthday Paradox
- LightOJ 1104 - Birthday Paradox【概率】
- birthday paradox
- Birthday Paradox
- CF679A Bear and Prime 100(prime)
- Android map api密匙获取 输入命令后显示keytool 不是内部或外部命令
- angulsrjs2.0---demo---使静态文字每秒随机变颜色
- git rebase简介(高级篇)
- $.ajax()方法详解
- 【Light OJ 1104】Birthday Paradox
- JUC集合-09之 LinkedBlockingDeque
- Jmeter使用
- CS231n课程笔记翻译系列之目录汇总
- spring学习(一)spring依赖注入四种底层方法
- ZKW线段树讲解
- NYOJ 364 & HDU 1052 田忌赛马(贪心)
- 微信小程序轮播图的实现
- linux终端如何设置光标位置