链接:

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. 网络编程介绍,C/S 架构,网络通讯协议,osi七层

    网络编程: 什么是网络编程: 网络通常指的是计算机中的互联网,是由多台计算机通过网线或其他媒介相互链接组成的 编写基于网络的应用程序的过程序称之为网络编程 为什么要学习网络编程: 我们已经知道计算机, ...

  2. IDEA 控制台中文乱码的问题

    -Dfile.encoding=UTF-8

  3. Nginx安装出现‘struct crypt_data’没有名为‘current_sal

    centos 安装nginx 时出现src/os/unix/ngx_user.c:26:7: 错误:‘struct crypt_data’没有名为‘current_sal 解决办法: 将系统换成版本低 ...

  4. 【Linux开发】linux设备驱动归纳总结(八):2.总线、设备和驱动的关系

    linux设备驱动归纳总结(八):2.总线.设备和驱动的关系 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  5. sublime text 修改侧边栏字体大小

    ctrl+shift_p 安装PackageResourceViewer,通过**PackageResourceViewer **这个插件来实现. 打开这个插件,选择Open Resource 输入T ...

  6. netcore发布的坑

    当我选择目标运行时为Linux-64时,生成的接口为第二图, 而当我选择目标运行时为可移植或windows-64时,生成的接口则是正确的.和我写的代码,以及本地按F5启动调试的效果一致. 整个项目从v ...

  7. hadoop3.1.2启动和停止

    1/  启动 启动zookeeper: 三个节点上都zkServer.sh start 启动hdfs和yarn: 101上start-dfs.sh  102上start-yarn.sh 启动hive: ...

  8. (5.8)mysql高可用系列——MySQL中的GTID复制(实践篇)

    一.基于GTID的异步复制(一主一从)无数据/少数据搭建 二.基于GTID的无损半同步复制(一主一从)(mysql5.7)基于大数据量的初始化 正文: [0]概念 [0.5]GTID 复制(mysql ...

  9. Hadoop系列读书笔记

    <Hadoop应用架构>是Orilley旗下精品系列的图书 Hadoop序列化 Thrift 不支持内部压缩 不能分片 缺少MapReduce的原生支持 Protocol Buffers ...

  10. vue : 无法加载文件 C:\Users\lihongjie\AppData\Roaming\npm\vue.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 htt ps:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。 所在位置 行:1 字符: 1 + vue init webpack vue_p

    以管理员方式打开powershell 运行命令:set-ExecutionPolicy RemoteSigned 出现: 执行策略更改执行策略可帮助你防止执行不信任的脚本.更改执行策略可能会产生安全风 ...