题解:从递推公式中找到规律,a1 = (a - C + n * a0) / (n + 1) 其中a是an+1,C是2 * n *c1 + 2 * (n - 1) * c2 + ... + 2 * cn 。
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 3005;
int main() {
double a0, c[N], C, a, ans;
int cases, n;
scanf("%d", &cases);
while (cases--) {
C = ans = 0;
scanf("%d", &n);
scanf("%lf%lf", &a0, &a);
for (int i = 1, j = n; i <= n; i++, j--) {
scanf("%lf", &c[i]);
c[i] = 2 * c[i] * j;
C += c[i];
}
ans = (a - C + n * a0) / (n + 1);
printf("%.2lf\n", ans);
if (cases)
printf("\n");
}
return 0;
}