链接:

https://vjudge.net/problem/LightOJ-1104

题意:

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.

思路:

考虑至少两个人生日同一天(Pa) = 1-所有人生日不同(Pb)

即当(Pb)<=0.5时满足条件.Pb = 1(n-1)/n(n-2)/n...

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; int n; int main()
{
int t, cnt = 0;
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
double p = 1;
int sum = n;
int res = 0;
while (p > 0.5)
{
sum--;
p = p*sum/n;
res++;
}
printf("Case %d: %d\n", ++cnt, res);
} return 0;
}

LightOJ-1104-birthday Paradox(概率)的更多相关文章

  1. LightOJ - 1104 Birthday Paradox —— 概率

    题目链接:https://vjudge.net/problem/LightOJ-1104 1104 - Birthday Paradox    PDF (English) Statistics For ...

  2. LightOj 1104 - Birthday Paradox(生日悖论概率)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1104 题意:一年365天,在有23个人的情况下,这23个人中有两个人生日相同的概率是大 ...

  3. lightoj 1104 Birthday Paradox

    题意:给定一个一年的天数,求最少多少人可以使至少两人生日同一天的概率不少于0.5. 用二分去做.检验一个数是否符合时,刚开始实用普通的方法,直接计算,超时了~~,上网搜了一下代码,一位大神使用一个数组 ...

  4. light oj 1104 Birthday Paradox (概率题)

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

  5. LightOJ - 1104 概率

    题意:每年n天,求最少几个人使这些人中最少两个人生日相同的概率大于0.5 题解:直接递推,假设有k个人,所有情况为n^k,没有相同的情况为n*(n-1)*...*(n-k+1),可以算出1e5以内不超 ...

  6. LightOJ 1030 Discovering Gold (概率/期望DP)

    题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...

  7. codeforces 711E. ZS and The Birthday Paradox 概率

    已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可 ...

  8. LightOJ 1104

    题意: 给你一年有n天,求至少有m人使得至少有两个人在同一天生日的概率不少于0.5. 分析: 任意两个人不在同一天生日的概率为C(n,m)*m!/n^m,它的对立事件A为至少有两个人在同一天生日, 则 ...

  9. LightOJ 1248 Dice (III) 概率

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

  10. LightOJ 1030 - Discovering Gold - [概率DP]

    题目链接:https://cn.vjudge.net/problem/LightOJ-1030 You are in a cave, a long cave! The cave can be repr ...

随机推荐

  1. 如何为根分区扩容(centos7为例)

    linux系统所有的文件都是存放在根分区中的,如果根分区容量即将耗尽,我们就需要给根分区扩容,我们可以使用lsblk命令来查看,系统的根分区实际是逻辑卷,所以想要扩展根分区只要将逻辑卷扩容就可以了.此 ...

  2. 【VS开发】获得devcon.exe

    1.获得devcon.exe 有两种方法,一是直接去网上下,不过下的很多64位的都不能用,二是自己装个ddk去安装目录下找,在WinDDK\7600.16385.1\tools\devcon下,当然还 ...

  3. C学习笔记-typedef

    typedef是一种高级数据特性,它能使某一类型创建自己的名字 typedef unsigned char BYTE; typedef struct man MAN; BYTE b = 0x12; 与 ...

  4. 【Spring AOP】Spring AOP的使用方式【Q】

    Spring AOP的三种使用方式 经典AOP使用方式 改进XML配置方式 基于注解的方式 第1种方式可以作为理解spring配置AOP的基础,是最原始的配置方式,也体现了spring处理的过程. 使 ...

  5. python并发编程-多线程实现服务端并发-GIL全局解释器锁-验证python多线程是否有用-死锁-递归锁-信号量-Event事件-线程结合队列-03

    目录 结合多线程实现服务端并发(不用socketserver模块) 服务端代码 客户端代码 CIL全局解释器锁****** 可能被问到的两个判断 与普通互斥锁的区别 验证python的多线程是否有用需 ...

  6. Python-RabbitMQ-fanout(广播模式)

    生产者:fanout_publiser.py import pika import sys connection = pika.BlockingConnection(pika.ConnectionPa ...

  7. C语言经典100例(1-50)

    [程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去掉不满足条件的排列. main ...

  8. 附录1:arrayanalysis的本地使用(质量控制)

    访问:https://github.com/BiGCAT-UM/affyQC_Module,点击“Download ZIP”,下载得到affyQC_Module-master.zip,解压得到一个af ...

  9. SQLServer 存储过程详解

    Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这样就可以提高存储过程的性能. Ø ...

  10. [转载]布隆过滤器(Bloom Filter)

    [转载]布隆过滤器(Bloom Filter) 这部分学习资料来源:https://www.youtube.com/watch?v=v7AzUcZ4XA4 Filter判断不在,那就是肯定不在:Fil ...