HDU 2086 A1 =? (Formula derivation)

Source: Internet
Author: User

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)

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.