acm--math--hdoj 2086--a1 =?

Source: Internet
Author: User


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,

  1. a1= (A0 +a2)/2-c1;
  2. a2= (A1 + A3)/2-c2, ...
  3. = = A1+A2 = (A0+A2+A1+A3)/2-(C1+C2)
  4. 2[(A1+A2) + (C1+C2)] = A0+A2+A1+A3;
  5. A1+A2 = A0+a3-2 (C1+C2);
  6. = = A1+A2 = A0+a3-2 (C1+C2)
  7. In the same vein, you get:
  8. A1+A1 = a0+a2-2 (C1)
  9. A1+A2 = A0+a3-2 (C1+C2)
  10. A1+A3 = A0+a4-2 (C1+C2+C3)
  11. A1+A4 = a0+a5-2 (C1+C2+C3+C4)
  12. ...
  13. A1+an = A0+an+1-2 (C1+C2+...+CN)
  14. Sum-----------------------------------------------------left and right
  15. (n+1) a1+ (A2+a3+...+an) = nA0 + (A2+a3+...+an) + an+1-2 (nc1+ (n-1) C2+...+2CN-1+CN)
  16. = = (n+1) A1 = nA0 + an+1-2 (nc1+ (n-1) C2+...+2CN-1+CN)
  17. = = 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 =?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.