AtCoder Code Festival 2017 Team Relay J - Indifferent
题目大意:共$2n$个价格$p_i$。两人轮流取。你每次取最大的,对方每次随机取。问你取的期望和是多少。
题解:从小到大排序,$\sum\limits_{i=0}^{2n-1} \frac{i*p_i}{2n-1}$
卡点:无
C++ Code:
#include<cstdio> #include<algorithm> using namespace std; long long n,s[200005]; long long ans; int main(){ scanf("%lld",&n); for (int i=0;i<n*2;i++)scanf("%lld",&s[i]); sort(s,s+n*2); for (long long i=0;i<n*2;i++)ans+=i*s[i]; printf("%.10lf",ans/(double)(2*n-1)); return 0; }