LightOJ
来源:互联网 发布:电气制图软件下载 编辑:程序博客网 时间:2024/06/14 16:28
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
这个题我想过二分答案然后用容斥倒着算进去…
但是看着T的大小….
很挫
百度题解发现竟然只要算出一个一个的占坑只要不重合概率小于二分之一就可以了。。
我真是傻了
不过这个思路记下来了,只要概率题不好做不妨反着想
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;int main(){ int T; cin >> T; int u = 0; while (T--) { int n; cin >> n; double p = 1; int r; for (int a = 1; a <= n; a++) { p *= (n - a) / double(n); if (p <= 0.5) { r = a; break; } } printf("Case %d: %d\n", ++u, r); }}
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- [LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- MySQL学习之锁(行锁、表锁、页锁、乐观锁、悲观锁等)
- Android webview解决JS报错chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'getItem'
- Mock方法介绍
- 学习kotlin第15天_操作符重载、空安全、异常、注解
- model 弹出后 bootstrap colorpicker 不显示颜色提取框 问题解决
- LightOJ
- 安装pycaffe所遇到的问题以及解决
- c++ 由几月几号出本年第多少天,考虑闰年
- Python机器学习应用 | 期末大作业1(程序设计)
- html5实现 搜索历史记录【轻松搞定】
- Leetcode 606. Construct String from Binary Tree
- Android-QQ登录
- Unity5.x学习笔记(3)-文件上传错误:unsupported protocol
- python入门系列13―——集合、双端队列、堆