Hdoj Title Address: Portal
A1 =?Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 6965 Accepted Submission (s): 4330
Problem description has the following equation: Ai = (Ai-1 + ai+1)/2-ci (i = 1, 2, 3, ...).
If given A0, an+1, and C1, C2, ..... Cn.
Please program calculate 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.
Sample Input
150.0025.0010.00250.0025.0010.0020.00
Sample Output
27.5015.00
because: 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)
- In the same vein, you get:
- 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)
- Sum-----------------------------------------------------left and right
- (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 <iostream> #include <cstdio>using namespace Std;int main () { int i,j,n; Double sum; while (scanf ("%d", &n)!=eof) { sum=0; Double a[3500],c[3500],d; 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]; 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; }
acm--math--hdoj 2086--a1 =?