集训第六周 数学概念与方法 概率 F题
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
每个人都有自己的生日,如果一群人站在一起,那么他们有至少两个人生日相同的概率是多少? 例如有任意22个人站在一起,概率就能达到0.5
所以问你给出一年的时间长(不一定是365天,有可能是火星来的),需要选出至少多少人才能使概率不低于0.5
方法:选N个人,这一群人生日都不相同的概率是P=364/365+363/365+362/365.........
最后使得P小于等于0.5就行了
#include"iostream"
#include"cstdio"
using namespace std;
int main()
{
int T,ca=;
cin>>T;
while(T--)
{
int year,sel;
cin>>year;
sel=year;
int ans=;
double p=1.0;
while(p>0.5)
{
ans++;
sel--;
p*=(sel*1.0)/year;
}
printf("Case %d: %d\n",ca++,ans);
}
return ;
}
O(O_O)O
集训第六周 数学概念与方法 概率 F题的更多相关文章
- 集训第六周 数学概念与方法 概率 N题
N - 概率 Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status ...
- 集训第六周 数学概念与方法 概率 数论 最大公约数 G题
Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...
- 集训第六周 数学概念与方法 数论 筛素数 H题
Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“ ...
- 集训第六周 数学概念与方法 计数 排列 L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...
- 集训第六周 数学概念与方法 J题 数论,质因数分解
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...
- 集训第六周 数学概念与方法 数论 线性方程 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...
- 集训第六周 数学概念与方法 UVA 11181 条件概率
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概 ...
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- 集训第六周 古典概型 期望 D题 Discovering Gold 期望
Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...
随机推荐
- 标准字符cp功能
#include<stdio.h> #include<fcntl.h> int main(int argc,char *argv[]) { FILE *src_fp,*des_ ...
- typedef struct和struct 的区别 用途
刚刚想到的,我们在用结构体的时候会遇到'->'和'.',这是什么情况呢? 不能混用的(c和c++不同语言对它们没有影响) 我说的不能混用的意思是'.'用于结构体指针的指向......而'-& ...
- Hdu 5407 CRB and Candies (找规律)
题目链接: Hdu 5407 CRB and Candies 题目描述: 给出一个数n,求lcm(C(n,0),C[n,1],C[n-2]......C[n][n-2],C[n][n-1],C[n][ ...
- C# 代码笔记_tuple元组
tuple元组: 赋值 List<Tuple<string, int>> cc = new List<Tuple<string, int>>() { n ...
- AJPFX详解泛型中super和extends关键字
首先,我们定义两个类,A和B,并且假设B继承自A.下面的代码中,定义了几个静态泛型方法,这几个例子随便写的,并不是特别完善,我们主要考量编译失败的问题: Java代码 public class Ge ...
- AJPFX关于java数组排序
/** *将数组中的两个指定下标的元素交换位置 *@param arr 要交换元素的数组引用地址值 *@param a 数组索引 ...
- [BZOJ2456]mode 其它
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2456 这道题有着神奇的内存限制1MB也就是说我们是没办法把读入的数字存下来的. 由于答案求 ...
- 机器学习-牛顿方法&指数分布族&GLM
本节内容 牛顿方法 指数分布族 广义线性模型 之前学习了梯度下降方法,关于梯度下降(gradient descent),这里简单的回顾下[参考感知机学习部分提到的梯度下降(gradient desce ...
- QML中使用相对路径
QML里有三种路径: 默认使用URL路径. "qrc:///filepath".这用来索引资源文件. "file:///绝对路径".这用来索引本地文件系统中的文 ...
- qt creator转换到 COFF 期间失败: 文件无效或损坏
转载请注明出处http://www.cnblogs.com/dachen408/p/7226198.html 环境 Qt5.5+Vs2010,删除vs2010安装目录bin下的cvtres.exe解决 ...