Has the following equation: aI= (AI-1FI+1)/2-cI(i = 1, 2, 3, .... n).
If you give an A0AN+1, and C1C2, ..... CN.
Please program calculation a1 =?
Input inputs include 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.
Output for each test instance, the A1 (Reserved 2 decimal places) is evaluated in one line.
Ideas:
Push formula:
First, you can roll out a formula 1:a1+an+2∑[1,n]ci = A0+a (n+1)
So:
A1+a1+2∑[1,1]ci = A0+a2
A1+a2+2∑[1,2]ci = A0+a3
A1+a3+2∑[1,3]ci = A0+a4
.....
A1+an+2∑[1,n]ci = a0+an+1
Add up on the left side = right add up, simplify, get:
(n+1) A1+2 (...) = Na0+a (n+1)
Code:
Doublec[3005];DoubleAx,ay;intMain () {intN; while(cin>>N) {cin>>ax>>ay; c[0]=0.0; Rep (I,1, N) { Doublex; CIN>>x; C[i]=c[i-1]+x; } Doubleres1=0.0; Rep (I,1, N) res1+=(C[i]); Res1*=2; printf ("%.2lf\n", (n*ax+ay-res1)/(n+1)); }}
HDU 2086 A1 =? (Formula derivation)