设dp[i]表示掷了i次的期望得分dp[1]=sigma(A[i])/N,dp[i]=dp[i-1]*M/N
可以看出dp数组构成了一个等比数列
ans=sigma(dp[i])=dp[1]*(1-(M/N)^n)/(1-M/N)
当n趋近+oo时(M/N)^n趋近于0,则ans=dp[1]/(1-M/N)=sigma(A[i])/(N-M)
特判当dp[1]!=0且N=M时ans=inf
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define maxn 205 4 double A[maxn],B[maxn]; 5 int main(){ 6 int n,m; 7 while(scanf("%d",&n)!=EOF){ 8 double all=0; 9 for(int i=1;i<=n;i++){ 10 scanf("%lf",&A[i]); 11 all+=A[i]; 12 } 13 scanf("%d",&m); 14 for(int i=1;i<=m;i++) 15 scanf("%lf",&B[i]); 16 if(all==0)printf("%.2lf ",0.0); 17 else if(n==m)printf("inf "); 18 else printf("%.2lf ",all/(n-m)); 19 } 20 return 0; 21 }