Uva-10014-simple Calculations (Classic math derivation!!) )

Source: Internet
Author: User

UVA-10014

Simple calculations
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

Description


Simple calculations

The problem

There is a sequence of n+2 elements a0, A1,..., An+1 (n <=, -1000 <= AI 1000). It is known this ai = (ai–1 + ai+1)/2–ci for each i=1, 2, ..., N. You are given A0, an+1, C1, ..., CN. Write A program which calculates A1.

The Input

The first line was the number of test cases, followed by a blank line.

For each test case, the first line of a input file contains an integer n. The next lines consist of numbers a0 and an+1 each have a digits after decimal point, and the next n lines contain Numbers CI (also with the digits after decimal point), one number per line.

Each test case is separated by a.

The Output

For each test case, the output file should contain A1 in the same format as A0 and an+1.

Print a blank line between the outputs for the consecutive test cases.

Sample Input
1
1
50.50
25.50
10.15
Sample Output
27.85

Source

Root:: Prominent problemsetters:: Alex Gevak
Root:: Competitive programming 3:the New Lower Bound of programming contests (Steven & Felix Halim):: Mathematics: : Ad Hoc Mathematics problems:: Finding Pattern or Formula, easier
Root:: Competitive programming 2:this increases the lower bound of programming contests. Again (Steven & Felix Halim):: Mathematics:: Ad Hoc Mathematics problems:: Finding Pattern or Formula
Root:: AOAPC i:beginning algorithm Contests (Rujia Liu):: Volume 1. Elementary Problem Solving:: Maths-misc



Very classical mathematical deduction!!!


First, according to test instructions a[i] = (A[i-1] + a[i+1])/2-c[i];

Transform can get a[i+1] = (A[i] + c[i]) * 2-a[i-1];

Then a[n+1] = (A[n] + c[n]) * 2-a[n-1]

= [(A[n-1] + c[n-1]) * 2-a[n-2] + c[n]] * 2-a[n-1]

= 3*a[n-1]-2*a[n-2] + 4*c[n-1] + 2*c[n]

= 4*a[n-2]-3*a[n-3] + 6*c[n-2] + 4*c[n-1] + 2*c[n]

= 5*a[n-3]-4*a[n-4] +8*c[n-3] + 6*C[n-2] + 4*c[ N-1] + 2*C[n]

....

= (n+1) *a[1]-n *a[0] + (n+1-i) * 2 * c[i] + ....


Then A[1] * (n+1) = a[n+1] + n*a[0]-(n+1-i) *2*c[i] + .....

The hand knocks really slow ...

AC Code:




Uva-10014-simple Calculations (Classic math 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.