A1 =?Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 5116 Accepted Submission (s): 3265
problem Descriptionthere are the following equations: Ai = (Ai-1 + ai+1)/2-ci (i = 1, 2, 3, .... n).
If given A0, an+1, and C1, C2, ..... Cn.
Please program calculate A1 =?
InputThe input includes multiple test instances.
For each instance, the first is a positive integer n, (n <= 3000); Then there are 2 numbers a0, an+1. The next n rows have a number ci (i = 1, .... n) per line; the input ends with a file terminator.
Outputfor each test instance, a row is used to output the calculated A1 (retain 2 decimal places).
Sample Input
150.0025.0010.00250.0025.0010.0020.00
Sample Output
27.5015.00Problem Solving Ideas:Pure math problem, find the law: an = (An-1) + (an+1-cnan-1) = (2/3) An-2 + (1/3) an+1-(2/3) Cn-(4/3) cn-1an-2 = (3/4) An-3 + (quarter) an+1- (1/2) Cn-cn-1-(3/2) cn-2an-3 = (4/5) An-4 + (1/5) an+1-(2/5) Cn-(4/5) Cn-1-(6/5) Cn-2-(8/5) Cn-3 ... (Does it feel a little bit) then: A1 = (n/(n+1)) A0 + (1/(n+1)) an+1-(2/(n+1)) Cn-(4/(n+1)) Cn-1-...-(2n/(n+1)) C1 = [nA0 + an+1-2 (Cn + 2cn-1 + 3cn-2 + ... + nC1)]/(n+1)Source code:#include <stdio.h> #include <stdlib.h> #define MaxSize 3001int Main () {int i,n; Double a1,a0,end; Double c[maxsize]; while (scanf ("%d", &n)!=eof) {scanf ("%lf%lf", &a0,&end); for (i=0;i<n;i++) scanf ("%lf", &c[i]); A1 = n A0 + end; for (i=0;i<n;i++) a1-=2* (i+1) *c[n-1-i]; A1 =a1/(1 + N); printf ("%.2lf\n", A1); } system ("Pause"); return 0;}
A1 =?