Ultraviolet A 10014-simple calculations

Source: Internet
Author: User

 Simple calculations 

The Problem

There is a sequence of N + 2 elements A0, A1 ,..., An + 1 (n <= 3000;-1000 <= ai 1000). It is known that
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 is the number of test cases, followed by a blank line.

For each test case, the first line of an input file contains an integer n. the next two lines consist of numbers A0 and an + 1 each having two digits after decimal point, and the next n lines contain numbers Ci (also with two
Digits after decimal point), one number per line.

Each test case will be separated by a single line.

The output

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

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

Sample Input
1150.5025.5010.15
Sample output
27.85

A [I] = (a [I-1] + A [I + 1])/2-C [I];
2 * (a [I] + C [I]) = A [I-1] + A [I + 1]

A [1]-A [0] = A [2]-A [1]-2 * C [1]
A [2]-A [1] = A [3]-A [2]-2 * C [2]
...
A [I]-A [I-1] = A [I + 1]-A [I]-2 * C [I]
A [I]-A [0] = A [I + 1]-A [1]-2C

A [1] = A [I + 1]-A [I] + A [0]-2C (n) [n items and]
Do this no idea, it is estimated that most people and I Y-Y, as long as the accumulation of the answer will come out.
Success means sticking to what has already been done. O (success _ success) O Haha ~
N = 1 A [1] = A [2]-A [1] + A [0]-2C (1)
N = 2 A [1] = A [3]-A [2] + A [0]-2C (2)
N = 3 A [1] = A [4]-A [3] + A [0]-2C (3)
N * A [1] = A [n + 1]-A [1] + N * A [0]-2 * [C (1) +... C (n)]

(N + 1) A [1] = A [n + 1] + N * A [0]-2 * [C (1) + C (n)]

 

# Include <stdio. h>
# Include <math. h>
Void main ()
{Double C [3001], s [3001], X, Y;
Int N, I, T;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N );
Scanf ("% lf", & X, & Y );
For (I = 1; I <= N; I ++)
Scanf ("% lf", & C [I]);
S [1] = C [1]; s [0] = s [1];
For (I = 2; I <= N; I ++)
{S [I] = s [I-1] + C [I];
S [0] + = s [I];
}
Printf ("%. 2lf \ n", (N * x + y-2 * s [0])/(n + 1 ));
If (t) printf ("\ n ");
}
}

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.