F - 概率(经典问题)

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit Status

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种不同的搭配。

程序代码:

  1. #include <cstdio>
  2. using namespace std;
  3. const int L=;
  4. double d[L];
  5. int n;
  6. int main()
  7. {
  8. int t,Case=;
  9. scanf("%d",&t);
  10. while(t--)
  11. {
  12. scanf("%d",&n);
  13. int ans=;
  14. double p=,pz=1.0;
  15. while(p<0.5)
  16. {
  17. pz=pz*(-ans*1.0/n);
  18. p=-pz;
  19. ans++;
  20. }
  21. printf("Case %d: %d\n",++Case,ans-);
  22. }
  23. return ;
  24. }

数学概念——F 概率(经典问题)birthday paradox的更多相关文章

  1. Math concepts / 数学概念

    链接网址:Math concepts / 数学概念 – https://www.codelast.com/math-concepts-%e6%95%b0%e5%ad%a6%e6%a6%82%e5%bf ...

  2. 21副GIF动图让你了解各种数学概念

    baidu 21副GIF动图让你了解各种数学概念

  3. 转:21副GIF动图让你了解各种数学概念

    21副GIF动图让你了解各种数学概念

  4. 集训第六周 数学概念与方法 概率 F题

    Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...

  5. F - 概率(经典问题)

    Description Sometimes some mathematical results are hard to believe. One of the common problems is t ...

  6. 动态规划之经典数学期望和概率DP

    起因:在一场训练赛上.有这么一题没做出来. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6829 题目大意:有三个人,他们分别有\(X,Y,Z\)块钱 ...

  7. 数学概念——E 期望(经典问题)

    E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

  8. 集训第六周 数学概念与方法 概率 N题

    N - 概率 Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status ...

  9. 集训第六周 数学概念与方法 概率 数论 最大公约数 G题

    Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...

随机推荐

  1. javascript动画效果

    之前工作项目中,运用了缓动动画的效果,在网上看到其他大牛写的相关公式,结合工作需要,进行了整理,拿出来跟大家分享下,js代码中,只运用了一个小功能进行了测试 <!DOCTYPE html> ...

  2. window.showModalDialog 子窗口和父窗口不兼容最新的谷歌

    最新版的谷歌不支持window.showModalDialog的写法,会出现,找不到方法的问题,同时返回值的方法window.dialogArguments;也用不了. 这里就只能用最原版的windo ...

  3. 开通博客第一天 (先发一些android(java)常见异常信息

    常见异常: java.lang.AbstractMethodError抽象方法错误.当应用试图调用抽象方法时抛出. java.lang.AssertionError断言错.用来指示一个断言失败的情况. ...

  4. Elasticsearch学习2--Elasticsearch数据类型简介

    1.Elasticsearch 是 面向文档型数据库,这意味着它存储的是整个对象或者 文档,它不但会存储它们,还会为他们建立索引,这样你就可以搜索他们了.你可以在 Elasticsearch 中索引. ...

  5. 2016.7.13final 修饰符使用

    final修饰符可以修饰类.变量.函数: 1.被final所修饰的类不能被继承,函数不能被继承,成员变量不能再次被赋值并且被称为常量: 2.被final 修饰的成员变量 .它通常被static所修饰, ...

  6. 扩展欧几里得算法(extended Euclidean algorithm)的一个常犯错误

    int exGcd(int x,int y,int& a,int& b) //ax+by=gcd(x,y) { ; b=; return x; } int res=exGcd(y,x% ...

  7. Windows程序设计 贪吃蛇c

    看Windows程序有段时间了,终于动手写东西.贪吃蛇算是一个开始吧,下面的贪吃蛇很简单,也有很多地方需要修改,还有情况没有考虑QAQ 但这不是我的目的了... 思路很简单:建个链表储存蛇身节点即可. ...

  8. Qt经典出错信息之”Basic XLib functionality test failed!”

    解决方法: 此完整出错信息是在./configure阶段Basic XLib functionality test failed!You might need to modify the includ ...

  9. 【POJ2761】【区间第k大】Feed the dogs(吐槽)

    Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs ...

  10. thinksns消息提示的实现机制(转)

    转自:http://jingyan.baidu.com/article/f25ef2541718eb482c1b8215.html thinksns的消息提示不是实时的,而是1分钟向服务器请求一次,再 ...