lightoj-1104-Birthday Paradox【概率】(思维)
来源:互联网 发布:马尔科夫矩阵 编辑:程序博客网 时间:2024/06/02 10:12
题目链接:点击打开链接
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 问你除了主人之外 再邀请几个人可以满足以上条件
题解:正着算比较麻烦 我们可以算出不相同的概率,我们一个一个的加:当只邀请一个人 生日不相同的概率为 364/365 邀请两个人为364/365 * 363/365 以此类推
#include<cstdio>#include<algorithm>#include<cmath>using namespace std;int n;int main(){int t,text=0;scanf("%d",&t);while(t--){scanf("%d",&n);int cnt=1;double per=0,a=1;while(per<0.5){a=a*(n-cnt)/n;per=1-a;cnt++;}printf("Case %d: %d\n",++text,cnt-1);}return 0;}
- lightoj-1104-Birthday Paradox【概率】(思维)
- LightOJ 1104 Birthday Paradox (离散概率)
- 【LightOJ 1104】Birthday Paradox(概率DP)
- LightOJ 1104 - Birthday Paradox【概率】
- LightOJ 1104 Birthday Paradox 概率(生日悖论)
- LightOJ 1104 Birthday Paradox【数学概率】
- lightoj 1104 Birthday Paradox 概率期望
- LightOJ 1104 Birthday Paradox(生日悖论,思维)
- Light OJ:1104 Birthday Paradox(数学概率+思维)
- 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(组合数学)
- LightOJ 1104 生日悖论(Birthday paradox)(概率抽屉原理)
- Light oj 1104 Birthday Paradox (生日悖论----概率)
- scala基础----trait操作
- 中缀表达式转换成后缀表达式并求值
- 广播机制一(广播接收器)
- 基于TF-IDF算法的五亿姓名数据分析
- POJ-2488 A Knight's Journey (DFS)
- lightoj-1104-Birthday Paradox【概率】(思维)
- 树-堆结构练习——合并果子之哈夫曼树
- android_ListView优化
- HDU.1896 Stones【优先队列】【模拟】【8月13】
- ios客户端安全性问题分析及处理方式
- Python模块扩展之AES算法
- 矩阵快速幂——RGB plants (Gym 101061 B)
- 成员函数和友元函数 完成二元和一元运算符重载(进阶1)
- 深度学习在人脸识别中的应用 ——优图祖母模型的“进化”