/* 因为:Ai=(Ai-1+Ai+1)/2 - Ci, A1=(A0 +A2 )/2 - C1; A2=(A1 + A3)/2 - C2 , ... => A1+A2 = (A0+A2+A1+A3)/2 - (C1+C2) 2[(A1+A2)+(C1+C2)] = A0+A2+A1+A3; A1+A2 = A0+A3 - 2(C1+C2); => A1+A2 = A0+A3 - 2(C1+C2) 同理可得: A1+A1 = A0+A2 - 2(C1) A1+A2 = A0+A3 - 2(C1+C2) A1+A3 = A0+A4 - 2(C1+C2+C3) A1+A4 = A0+A5 - 2(C1+C2+C3+C4) ... A1+An = A0+An+1 - 2(C1+C2+...+Cn) ----------------------------------------------------- 左右求和 (n+1)A1+(A2+A3+...+An) = nA0 +(A2+A3+...+An) + An+1 - 2(nC1+(n-1)C2+...+2Cn-1+Cn) => (n+1)A1 = nA0 + An+1 - 2(nC1+(n-1)C2+...+2Cn-1+Cn) => A1 = [nA0 + An+1 - 2(nC1+(n-1)C2+...+2Cn-1+Cn)]/(n+1) */ #include <cstdio> #include <iostream> using namespace std; const int maxn = 3003; double a[maxn], c[maxn]; int main() { int n, i, j; while (scanf("%d", &n) == 1) { scanf("%lf%lf", &a[0], &a[n + 1]); for (i = 1; i <= n; i++) scanf("%lf", &c[i]); a[1] = n * a[0] + a[n + 1]; double sum = 0; for (i = n, j = 1; i >= 1 && j <= n; j++, i--) sum += i * c[j]; a[1] = (a[1] - 2 * sum) / (n + 1); printf("%.2lf\n", a[1]); } return 0; }
//递推题: //a[1]=1/(n+1)*(a[n+1]+n*a[0]-2*c[n]-4*c[n-1]-8*c[n-2]...-pow(2,n)*c[1]); #include<stdio.h> int main() { int n,i,k; float a[3005],c[3005]; float sum; while(~scanf("%d",&n)) { scanf("%f%f",&a[0],&a[n+1]); for(i=1;i<=n;++i) scanf("%f",&c[i]); k=2; sum=0; for(i=n;i>0;--i) { c[i]*=k; k+=2; sum+=c[i]; } printf("%.2f\n",1.0/(n+1)*(a[n+1]+n*a[0]-sum)); } return 0; }
//n = 1时,有 a1 = a0/2 + a2/2 - c1 //n = 2时,有 3/2*a1 = a0 + a3/2 - 2*c2 - c1 //n = 3时,有 2*a1 = 3*a0/2 + a4/2 - 3*c3 - 2*c2 - c1 //所以得出 //n = k 时,有 (n+1)/2 * a1 = (n/2)*a0 + a(n+1)/2 - n*cn - …-2*c2 - c1 #include <stdio.h> int main(){ int n,i; double a0,an,c[3005]; while(~scanf("%d",&n)){ scanf("%lf%lf",&a0,&an); for(i = 1;i<=n;i++) scanf("%lf",&c[i]); double ans,t = 0; for(i = 1;i<=n;i++) t = t+(n-i+1)*c[i]; ans = a0*(0.5*n)+an/2.0-t; ans/=(0.5*(n+1)); printf("%.2lf\n",ans); } return 0; }