这个题是典型的数学递推题,把求a1的公式算出来,这道题便解决了。
由2ai = ai–1 + ai+1 – 2ci,将i = 1,2,3,4……n带入,得:
2a1 = a0 + a2 - 2c1
2a2 = a1 + a3 - 2c2
2a3 = a2 + a4 - 2c3
…… …… ……
2an = an-1 + an+1 - 2cn,
然后保留第一个式子i, 并从第一个式子往下加,又得到n个式子:
2a1 = a0 + a 2 - 2c1
a1 + a2 = a0 + a3 - 2(c1 + c2)
a1 + a3 = a0 + a4 - 2(c1 + c2 + c3)
…… …… …… ……
a1 + an = a0 + a - 2(c1 + c2 + c3 + …… + cn)
n个式子相加,得:
(n + 1)a1 = na0 + an+1 - 2(nc1 + (n-1)c2 + (n-2)c3 + …… + cn),便可求出答案.
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define pi acos(-1.0)
#define eps 1e-8
//#define spongewxy_code
using namespace std;
int main() {
#ifdef spongewxy_code
freopen("aa.in", "r", stdin);
freopen("bb.out", "w", stdout);
#endif
int T, n;
double ans, m, x, y;
int kcase = 0;
cin >> T;
while(T--) {
if(kcase) {
puts("");
}
kcase++;
cin >> n;
cin >> x >> y;
ans = 0.0;
ans += (n * x + y);
for(int i = 1; i <= n; ++i) {
cin >> m;
ans -= 2 * (n - i + 1) * m;
}
printf("%.2lf\n", ans / (n + 1.0));
}
return 0;
}