数学期望
G.Glass Bead Game
题解:关键的点是考虑多个太麻烦,不妨只考虑两个之间的关系,则i在j前面的概率为\(\frac{pj}{pi+pj}\),其它的是不用考虑,因为不影响他们之间的先后关系。通过这个结论,稍加思考就可以得到答案。
#include<bits/stdc++.h>
using namespace std;
const int N = 104;
double p[N];
int main(){
int n;
cin >> n;
for(int i =1;i<=n;i++)cin >> p[i];
double res = 0;
for(int i=1;i<=n;i++){
double tp = 0;
for(int j=1;j<=n;j++){
if(i==j)continue;
tp += p[j]/(p[i]+p[j]);
}
tp *= p[i];
res += tp;
}
cout << fixed << setprecision(12) << res << endl;
}
浙公网安备 33010602011771号