数学概念——F 概率(经典问题)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
解题思路:
n≤365,根据鸽巢原理,n大于365时概率为1。
鸽巢原理:又称抽屉原理,或狄利克雷原理,被用来证明一些关于存在性的数学问题,并且在数论和密码学中也有广泛的应用
这里题目的意思是在N天中,两人在同一天生日的概率不超过0.5的概率,这样的人会来多少人才能满足
理解生日悖论的关键在于领会相同生日的搭配可以是相当多的。如在前面所提到的例子,23个人可以产生种不同的搭配,而这每一种搭配都有成功相等的可能。从这样的角度看,在253种搭配中产生一对成功的配对也并不是那样的不可思议。
换一个角度,如果你进入了一个有着22个人的房间,房间里的人中会和你有相同生日的概率便不是50:50了,而是变得非常低。原因是这时候只能产生22种不同的搭配。
程序代码:
#include <cstdio>
using namespace std;
const int L=;
double d[L];
int n;
int main()
{
int t,Case=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int ans=;
double p=,pz=1.0;
while(p<0.5)
{
pz=pz*(-ans*1.0/n);
p=-pz;
ans++;
}
printf("Case %d: %d\n",++Case,ans-);
}
return ;
}
数学概念——F 概率(经典问题)birthday paradox的更多相关文章
- Math concepts / 数学概念
链接网址:Math concepts / 数学概念 – https://www.codelast.com/math-concepts-%e6%95%b0%e5%ad%a6%e6%a6%82%e5%bf ...
- 21副GIF动图让你了解各种数学概念
baidu 21副GIF动图让你了解各种数学概念
- 转:21副GIF动图让你了解各种数学概念
21副GIF动图让你了解各种数学概念
- 集训第六周 数学概念与方法 概率 F题
Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...
- F - 概率(经典问题)
Description Sometimes some mathematical results are hard to believe. One of the common problems is t ...
- 动态规划之经典数学期望和概率DP
起因:在一场训练赛上.有这么一题没做出来. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6829 题目大意:有三个人,他们分别有\(X,Y,Z\)块钱 ...
- 数学概念——E 期望(经典问题)
E - 期望(经典问题) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- 集训第六周 数学概念与方法 概率 N题
N - 概率 Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status ...
- 集训第六周 数学概念与方法 概率 数论 最大公约数 G题
Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...
随机推荐
- [O] SQLite数据库报错:no such column
在SQLite数据库创建语句增加列,运行后报错:no such column 在语法规范的前提下,即 //SQLite数据库创建,逗号与空格须严格 String CREATE_NOTE = " ...
- [原创] Fragment的添加、移除问题
安卓一直在进化,Fragment就是个好东西,如果早5年做安卓开发,真要麻烦的多. 关于Fragment的讲解,这里很详尽: Android Fragment 真正的完全解析(上) Android F ...
- sql - 以半月,每月 分组
按半月:完整代码: SELECT siteNumber [站点], CONVERT(VARCHAR(7),day,120)+'-'+ case when day(day) between 1 and ...
- ST3破解命令
open terminal and input it! printf '\x39' | dd seek=$((0x6f35)) conv=notrunc bs=1 of=/Applicatio ...
- iOS 事件处理机制与图像渲染过程(转)
iOS 事件处理机制与图像渲染过程 iOS RunLoop都干了什么 iOS 为什么必须在主线程中操作UI 事件响应 CALayer CADisplayLink 和 NSTimer iOS 渲染过程 ...
- webpack学习笔记一(入门)
webpack集成了模块加载和打包等功能 ,这两年在前端领域越来越受欢迎.平时一般是用requirejs.seajs作为模块加载用,用grunt/gulp作为前端构建.webpack作为模块化加载兼容 ...
- 解决js浮点数计算bug
1.加 function add(a, b) { var c, d, e; try { c = a.toString().split(".")[1].length; } catch ...
- ejs 基本语法
1.基本语法.<% code %> 无缓冲的条件语句元素.<%= code %> 转义HTML,该code并且会打印出来.<%- code %> ...
- Java学习----对象间的继承
继承:子类可以使用父类非私有的成员变量和方法 public class Father { public String name; public String bloodType; private in ...
- 前端,移动开发者,UI须懂: 不同设备的之间的尺寸
在开发前端,移动APP,以及设计UI的时候,我们经常会去搜索不同设备之间的尺寸,来开始自己的工作,以保证显示效果达到更好,这里收集了现在常用的设备. 设备更新速度快,有些没罗列的,大家可以谷歌或者百度 ...