light oj 1104 Birthday Paradox (概率题)
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.
#include<cstdio>
int main()
{
int t,k=;
scanf("%d",&t);
while(t--)
{
double n,p=;
scanf("%lf",&n);
int i;
for(i=;;i++)
{
p*=((n-i)/n);
if(p <= 0.5)
break;
}
printf("Case %d: %d\n",++k,i);
}
light oj 1104 Birthday Paradox (概率题)的更多相关文章
- LightOJ - 1104 Birthday Paradox —— 概率
题目链接:https://vjudge.net/problem/LightOJ-1104 1104 - Birthday Paradox PDF (English) Statistics For ...
- Light OJ 1104 第六周F题
F - 概率(经典问题) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...
- 概率 light oj 1104
t个数据 n天一年 至少2个人在同一天生日的概率>=0.5 问至少多少人 显然要从反面考虑 设365天 都在不同一天的概率 p(num)=1*364/365*363/365...; =(day ...
- Light OJ 1104 Birthday Pardo(生日悖论)
ime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Description Sometime ...
- Light OJ 1050 - Marbles(概率DP)
题目大意: 一个包裹里有蓝色和红色的弹珠,在这个包裹里有奇数个弹珠,你先走, 你先从背包里随机的拿走一个弹珠,拿走每个弹珠的可能性是一样的.然后Jim从背包里拿走一个蓝色的弹珠,如果没有蓝色的弹珠让J ...
- Light OJ 1030 - Discovering Gold(概率dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
随机推荐
- (转)通过MySQL复制线程SQL_Thread加快增量恢复binlog
数据回档常常是使用全量备份+binlog增量实现的.而数据量很大的情况下,增量恢复binlog一直是一个苦恼的问题,因为恢复binlog速度十分慢,并且容易出错. 恢复binlog文件一般有两种方法: ...
- 升级到spring security5遇到的坑-密码存储格式
遇到的问题 将spring security oauth2(包括spring security)升级到最新,代码没有改动,运行项目没有报错,但是页面登陆时报错:There is no Password ...
- eclipse查看jar包源文件
话不多说上链接 https://www.cnblogs.com/1995hxt/p/5252098.html这里介绍了完整的流程,亲自试过,可以的! 以防以后要用的时候找不到文件的下载地址,所以就先在 ...
- 第十六章 提升用户体验 之 设计实现routes
1. 概述 ASP.NET MVC route 用来把URL映射到方法中的action,是用户和程序之间的桥梁. 本章内容包括:定义route处理URL Pattern.应用route限制.忽略URL ...
- ES5数组遍历
reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值. array.reduce(function(total, currentValue, curren ...
- 13.JAVA-包package、import使用
1.包的定义 之前我们学习java时,生成的class文件都是位于当前目录中,假如出现了同名文件,则会出现文件覆盖问题,因此就需要设置不同的目录(定义包),来解决同名文件冲突问题. 并且在大型项目中, ...
- Java基础:(一)数据类型
一.包装类型 基本类型都有对应的包装类型,基本类型与其对应的包装类型之间的赋值使用自动装箱与拆箱完成. 八个基本类型:boolean/1:byte/8:char/16:short/16:int/32: ...
- SQL SERVER 2014 缺少Business Intelligence 解决办法
SQL SERVER 2014安装完所有的数据库工具后,缺少开发工具 Business Intelligence 之解决办法. https://msdn.microsoft.com/en-us/l ...
- Android studio 3.1.1 找不到DDMS
先找到AndroidStudio配置的SDK路径: 在SDK的/tools/路径下[就是和配置ADB一样的路径]有个monitor.bat 的批处理文件: 鼠标连续点击两下monitor.bat这个批 ...
- Android 4.4及以后将内容布局延伸到状态栏
首先说明:该文章不是大家说的沉浸式状态栏,网上沉浸式状态栏的博客很多,搜索就有了! 该篇博客的主要目的就是为了将图片显示在状态栏上,让APP看起来更有型!如下图所示: 界面 这个界面的布局就是co ...