Question link: 10883-Supermean meaning: Calculate the super average, that is, calculate an average between two adjacent values until the next number is left, and calculate the value. Idea: drawing can easily infer the formula. Take the last group as an example. 1 2 3 4 5 1.5 2.5 3.5 4.5 2 3 4 2.5 3.5 3 observation can be found from the top to the end, looking at several other routes, there are several times, and then each number is divided by 2 of the corresponding number, which is the combination of C (n-1, [0-n-1. So ans = sum {C (n-1, I) * a [I]/2 ^ (n-1)} Then, because n is very large, it will be a tragedy. Therefore, each item takes the log value first, and then returns it to the power of the power, then each item is log (C (n-1, I) * a [I]/2 ^ (n-1) = log (C (n-1, I) + log (a [I])-(n-1) * log (2); finally, use the exp function to calculate the sum. The Code is as follows:
#include
#include
#include
#define min(a,b) ((a)<(b)?(a):(b))const int N = 50005;int t, n;double a, c;double cal(int i, double a) {return c + log(a) - (n - 1) * log(2);}int main() {int cas = 0;scanf("%d", &t);while (t--) {scanf("%d", &n);double sum = 0;c = 0;for (int i = 0; i < n; i++) {scanf("%lf", &a);if (a < 0) sum -= exp(cal(i, -a));else sum += exp(cal(i, a));c = c + log(n - i - 1) - log(i + 1);}printf("Case #%d: %.3lf\n", ++cas, sum);}return 0;}