LightOJ - 1104 Birthday Paradox

Give you the number of days of the year n at least ask how many people you want to invite (not his own) allows those of us who have at least two birthdays on the same day the probability is greater than 0.5

Topic Link

#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N = 1e5+7;
const double eps = 1e-10;
int dp[N];
int main(){
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int t;
    scanf("%d",&t);
    int w=0;
    for(int i=1;i<N;i++){
        double ans=1.0;
        for(int j=1;;j++){
            ans=ans*((i-j)*1.0/i);
            if(ans-0.5<eps){
                dp[i]=j;
                break;
            }
        }
    }
    while(t--){
        int n; scanf("%d",&n);
        printf("Case %d: %d\n",++w,dp[n]);
    }
}

 

Guess you like

Origin www.cnblogs.com/wmj6/p/11200590.html