Freebie

B - Freebie

期望=(sum_{i=1}^{365} 第i天为特殊天的概率)

把特殊天分为两类,一种是周末和周一,一种是周二三四五。

① 对于假设把周末和周一合并为一天,也使得这一天在一年中出现的概率为(frac{3}{365})

要求出这一天是特殊天的概率有点复杂,正难则反。于是令 p 为这一天不是特殊天的概率。

那么(p=(frac{362}{365})^n+C_n^1frac{3}{365}(frac{362}{365})^{n-1}),这一天为特殊天的概率则为(1-p)

因为这种天总共有52天,所以对答案的贡献为(52*(1-p))

②同理可以求得周二三四五的贡献。

// Created by CAD
#include <bits/stdc++.h>
using namespace std;

int main(){
    double ans=0;
    int n;cin>>n;
    double temp=1;
    for(int i=1;i<=n;++i)
        temp=temp*362/365;
    ans+=temp+1.0*n*3*temp/362;
    ans=(1.0-ans)*52;

    temp=1;
    for(int i=1;i<=n;++i)
        temp=temp*364/365;
    ans+=(365.0-52*3)*(1.0-temp-temp*n/364);

    printf("%.12f
",ans);
}
原文地址:https://www.cnblogs.com/CADCADCAD/p/13744526.html