LIGHT OJ-1104 Birthday Paradox 【组合】
来源:互联网 发布:js 图片热点 编辑:程序博客网 时间:2024/06/02 07:46
1104 - Birthday Paradox
Time Limit: 2 second(s) Memory Limit: 32 MB
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;
- 思路:设至少有x人, 使所有的生日都不在同一天的概率最大是0.5 即N*(N-1)……*(N-x+1) / N^x<=0.5;
- 失误:刚开始列式子用成了组合,都怀疑题目了,最后发现用分步乘法计算,还要好好看看组合了;最后竟然题意都看错了,竟然不包括自己,求的是邀请多少人!!!
- 代码如下:
#include<cstdio>using namespace std;#define esp 1e-9int main(){ int T; double N; int K=0; scanf("%d",&T); while(T--) { scanf("%lf",&N); double s=1.0;int cnt=0; while(s<2.0) { ++cnt; s*=N/(N-cnt+1); } printf("Case %d: ",++K); printf("%d\n",cnt-1);//不包括自己 } return 0;}
- LIGHT OJ-1104 Birthday Paradox 【组合】
- 【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 生日悖论-雀巢原理
- E - Birthday Paradox Light 1104
- 【LightOJ】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【概率】
- birthday paradox
- Primer STL笔记第二部分容器与算法
- nginx之location配置
- 华为OJ——判断两个IP是否属于同一子网
- 对于Sql模糊查询的话,需要对多个字段进行模糊查询的解决办法
- java导处excel
- LIGHT OJ-1104 Birthday Paradox 【组合】
- zcmu 1617: 补提交
- 对象的创建与引用计数器实现
- java虚拟机模型
- js查找高亮显示栏目
- linux sed命令详解
- select @@identity的用法
- word2vec原理及实现
- PAT-A 1004.Counting Leaves