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

程序代码:

#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的更多相关文章

  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. js自定义方法名

    自定义方法名: <script language="javascript" type="text/javascript">window.onload ...

  2. 怎样使用svn开发项目

    那么首先什么是svn呢?官方有很好的解释,我说一下个人简单的理解,svn就是开源的版本控制软件, 那么什么是版本呢?简单的说版本就是标记,比如你买了一本书,同样的书名,但是版本不一定一样, 因为里面可 ...

  3. HTML5 WebAudioAPI(三)--绘制频谱图

    HTML <style> #canvas { background: black; } </style> <div class="container" ...

  4. 学习java随笔第二篇:java开发工具——Eclipse

    java开发工具有很多这里我使用的是Eclipse. 首先我在官网上下载了Eclipse的软件包,下载地址:http://www.eclipse.org/downloads/,然后有在网上找了一个汉化 ...

  5. CentOS 5.4下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)

    原文链接:http://www.jb51.net/article/29668.htm

  6. Android EditText自动弹出输入法焦点

    http://mobile.51cto.com/aprogram-403138.htm 1. 看一个manifest中Activity的配置,如果这个页面有EditText,并且我们想要进入这个页面的 ...

  7. Oracle 10G强大的SQL优化工具:SQL Tuning Advisor

    p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 120%; orphans: 2; widow ...

  8. 效果类似于label从下往上滑(采用uiTableView实现)

    首先附上效果图 进行描述一下:效果就是类似于是一个竖直方向的滚动视图 并且方向是从下往上  并且能够一直这样循环下去. 代码“ // // ViewController.m // demo滚动视图上下 ...

  9. JavaScript 字符串(String) 对象

    JavaScript 字符串(String) 对象 String 对象用于处理已有的字符块. JavaScript 字符串 一个字符串用于存储一系列字符就像 "John Doe". ...

  10. Linux抓包工具tcpdump详解

    tcpdump是一个用于截取网络分组,并输出分组内容的工具,简单说就是数据包抓包工具.tcpdump凭借强大的功能和灵活的截取策略,使其成为Linux系统下用于网络分析和问题排查的首选工具. tcpd ...