数学题,首先推导出2*sum{c1,c2...cn} = (An+1-An) - (A1-A0),在将n个该式相加,可以推导出
(n+1)*A1=An+1+n*A0-2*sum{sum{c1,c2...cj}, j=1...n},即
(n+1)*A1=An+1+n*A0-2*sum{n*c1, (n-1)*c2...2*cn-1, cn}
A1可求。
1 #include <stdio.h> 2 3 int main() { 4 double a0, an1, c; 5 double a1; 6 int n, i; 7 8 while (scanf("%d", &n)!=EOF && n) { 9 scanf("%lf %lf", &a0, &an1); 10 a1 = an1+n*a0; 11 for (i=0; i<n; ++i) { 12 scanf("%lf", &c); 13 a1 -= 2*c*(n-i); 14 } 15 a1 /= (n+1); 16 printf("%.2lf ", a1); 17 } 18 19 return 0; 20 }