数学概念——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 ...
随机推荐
- HTML特效代码大全
1)贴图:<img src="图片地址">2)加入连接:<a href="所要连接的相关地址">写上你想写的字</a>1)贴 ...
- UMEditor 二次开发技术实践
许多项目都会或多或少的结合许多第三的组件,恰好,遇到了UMeditor富文本组件,因为它及其精简,功能强大,有专业团队维护,所以,我选择了它,而且它出色的完成项目中的全部功能的需求,对此,我说一下,二 ...
- .net 学习路线感想
从上到大学到现在工作,已经有六年多了,发现学习编程到以开发为工作也是一个挺长的过程的. 大学中,从c语言到java.C#到其他各种语言的学习,还有其他知识的学习如:数据库(oracle.sql Ser ...
- WCF存储图片到指定文件夹下
string path = System.IO.Directory.GetCurrentDirectory() + @"\POIImages\"; Guid imgid = Gui ...
- npm不能安装任何包,报错:npm WARN onload-script failed to require onload script npm-autoinit/autoinit及解决方法
想要利用Hexo搭建一个博客,但是安装时npm一直报错,不仅仅是Hexo包,连别的其他包也不行,会提示下面的一堆错误 npm WARN onload-script failed to require ...
- Vijos1386 IOI2007 矿工配餐 动态规划
感觉早些年IOI的题都不难啊,也就NOIp难度……现在貌似变难了 状态用dp[n][a1][b1][a2][b2]表示 n表示处理到前n个餐车 第一组矿工得到的最近一种食物用a1表示,a1的上一种食物 ...
- 对 const char* const &a 的理解
定义中用到&是独立引用. 比如: char i; char &a=i; 表示a是i的一个单独引用. 当有i='a'时,也有a='a'; 当有a='c'时,也有i='c'; 两个变量的标 ...
- SGU 220.Little Bishops(DP)
题意: 给一个n*n(n<=10)的棋盘,放上k个主教(斜走),求能放置的种类总数. Solution: 一眼看上去感觉是状压DP,发现状态太多,没办法存下来... 下面是一个十分巧妙的处理: ...
- 【BZOJ3110】【整体二分+树状数组区间修改/线段树】K大数查询
Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c 如果是2 a b c形式,表示询问从第a个位置到第b个位 ...
- c 连接数据库 mysql
sudo apt-get install mysql-server mysql-client 再装开发包代码:sudo apt-get install libmysqlclient15-dev 安装完 ...