HDU 2086 A1 =?

Source: Internet
Author: User

A1 =?

Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)

Total submission (s): 6492 Accepted Submission (s): 4038

Problem Description

There 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 programmatically calculate a1 =?

Input

The 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, ...) for each row, and the input ends with a file terminator.

Output

For each test instance, a row is used to output the calculated A1 (retain 2 decimal places).

Sample Input

1

50.00

25.00

10.00

2

50.00

25.00

10.00

20.00

Sample Output

27.50

15.00

Source

2006/1/15 ACM Program Design Final Exam

1 /* 2 ai= (ai-1+ai+1)/2-ci,3 a1= (A0 + A2)/2-c1;4 a2= (A1 + A3)/2-c2, ...5 = = A1+a2 = (A0+A2+A1+A3)/2-(C1+C2)6 2[(A1+A2) + (C1+C2)] = A0+A2+A1+A3;7 a1+a2 = a0+a3-2 (C1+C2);8 = = A1+A2 = A0+a3-2 (C1+C2)9 In the same vein, you get:Ten a1+a1 = a0+a2-2 (C1) One a1+a2 = a0+a3-2 (C1+C2) A a1+a3 = a0+a4-2 (C1+C2+C3) - a1+a4 = a0+a5-2 (C1+C2+C3+C4) -       ...  the 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) A */   at //!!! With CIN and cout will time out -#include <iostream> -#include <cstdio> - using namespacestd; - Doublea[3010],c[3010]; - intMain () in { -     intN; to      while(~SCANF ("%d",&N)) { +         Doublesum=0; -scanf"%LF%LF", &a[0],&a[n+1]); the          for(inti=n;i>=1; i--){ *scanf"%LF",&c[i]); $sum+=i*C[i];Panax Notoginseng         } -a[1]= (a[0]*n+a[n+1]-2*sum)/(n+1); theprintf"%.2f\n", a[1]); +     } A     return 0; the}

HDU 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.