日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【LightOJ - 1104】Birthday Paradox(概率,思维)

發(fā)布時(shí)間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【LightOJ - 1104】Birthday Paradox(概率,思维) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

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

題目大意:

已知星球上有n天,求邀請人數(shù)的最小值ans,滿足參加生日party上至少兩個(gè)人同一天生日的概率至少為0.5。

解題報(bào)告:

求至少兩個(gè)人同一天不是很好求,可以求問題的對立面,考慮任意兩個(gè)人都不是同一天的概率,每個(gè)人生日的概率是1/n,當(dāng)邀請的人數(shù)是ans,每個(gè)人生日都不同時(shí),概率為P。

則?

所以至少兩個(gè)人生日同一天的概率為1-P,只要1-P>0.5退出,最后答案為ans。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 10000 + 5; int n; int main() {int t,iCase=0;cin>>t;while(t--) {scanf("%d",&n);int ans = 0;double P = 1;while(P > 0.5) {ans++;P *= (1-ans*1.0/n);}printf("Case %d: %d\n",++iCase,ans);}return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【LightOJ - 1104】Birthday Paradox(概率,思维)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。