数学期望。

#include<bits/stdc++.h>
const int N=105;
using namespace std;
double d[N][N],p;
int main(){
    int T,n,a,b,cnt=0;double p;scanf("%d",&T);
    while(T--){
        memset(d,0,sizeof(d));
        scanf("%d/%d%d",&a,&b,&n);
        p=(double)a/b;
        d[0][0]=1;d[0][1]=0;
        for(int i=1;i<=n;i++)
        for(int j=0;j*b<=a*i;j++){
            if(!j) d[i][j]=d[i-1][j]*(1-p);
            else d[i][j]=d[i-1][j]*(1-p)+d[i-1][j-1]*p;
        }
        double q=0;
        for(int i=0;i<=n;i++)q+=d[n][i];
        printf("Case #%d: %d\n",++cnt,int(1/q));
    }
}

 

相关文章:

  • 2021-07-15
  • 2021-09-12
  • 2022-02-17
  • 2021-07-25
  • 2021-08-02
  • 2021-11-02
猜你喜欢
  • 2021-07-30
  • 2022-12-23
  • 2021-12-26
  • 2021-07-13
  • 2021-07-09
  • 2022-01-27
  • 2021-06-06
相关资源
相似解决方案