A1489. 抽奖(乔明达)
题解已经讲的很清楚了,就不鬼扯了,直接上代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 #define maxn 100005 3 double a[maxn],p[maxn]; 4 double qp(double base,int x){ 5 double ans=1; 6 while(x){ 7 if(x&1)ans=ans*base; 8 base=base*base; 9 x>>=1; 10 } 11 return ans; 12 } 13 int main(){ 14 int n,m; 15 scanf("%d%d",&n,&m); 16 int sum=0; 17 for(int i=1;i<=n;i++){ 18 scanf("%lf",&a[i]); 19 sum+=a[i]; 20 } 21 for(int i=1;i<=n;i++) 22 p[i]=a[i]/sum; 23 double ans1=0; 24 for(int i=1;i<=n;i++) 25 ans1+=p[i]*p[i]; 26 ans1=ans1*m*(m-1)+m; 27 double ans2=0; 28 for(int i=1;i<=n;i++) 29 ans2+=qp(1-p[i],m); 30 ans2=n-ans2; 31 printf("%.2lf\n%.2lf\n",ans1,ans2); 32 return 0; 33 }