【HackerRank|【HackerRank Week of Code 31】Colliding Circles

【【HackerRank|【HackerRank Week of Code 31】Colliding Circles】https://www.hackerrank.com/contests/w31/challenges/colliding-circles/problem
设E(n)为序列长度为n时的期望值。
\[ \begin{aligned} E(n-1)=&E(n)+\frac1{n\choose2}\sum_{0\leq i\(O(n)\)递推。

#include #include #include #include using namespace std; const int N = 100003; double a[N], sum = 0, E[N]; int n, k; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%lf", &a[i]), sum += a[i], E[n] += a[i] * a[i]; for (int i = 1; i <= k; ++i) { E[n - 1] = (1.0 - (2.0 / n / (n - 1))) * E[n] + sum * sum * 2 / n / (n - 1); --n; }printf("%.10lf\n", E[n] * acos(-1)); return 0; }

转载于:https://www.cnblogs.com/abclzr/p/9240529.html

    推荐阅读