Uvaoj 10014-simple calculations

Source: Internet
Author: User

I held a game on HUST and added some simple mathematical questions in Liu lujia's book.

Today, I am not going to go to the server. You still don't know what it looks like. Hust will return if the question is handed in.Judging Error 1.

Let's just explain this question first.

Question

This gives a formula A I =
( I-1 + I + 1)/2-C I  (1 <= I <= N ).
A is A 0 ,
A 1 ,..., A N + 1(N
<= 3000;-1000 <= I 1000) Yes Sequence of N + 2 Elements . Here you are. A 0 ,
A N + 1, C1,
..., CNYou need to findA1

Derivation:

First, superimpose the N formulas that can be obtained according to the formula, obtain a [1] + A [n] = A [0] + A [n + 1]-2 (C [1] + .... + C [N]), transformed to a [0]-A [1]-2 (C [1] +... + C [N]) = A [n]-A [n + 1]. Therefore, we can represent any A [k]-A [k + 1] as a [0]-A [1] (because C is known ). Perform another superposition. The left side of the formula is (a [0]-A [1]) + (A [1]-A [2]) +... (A [n]-A [n + 1])
= A [0]-A [n + 1], used on the rightA [0]-A [1], and the right side is (a [0]-A [1]) + (A [0]-A [1]-2 sigma (C [K], k = 1 ~ 1) +... = (n + 1) A [0]-(n + 1) A [1]-2 (SIGMA (C [1 ~ 1]) + sigma (C [1 ~ 2]) +... + sigma (C [1 ~ N]). in this way, only the iterative superposition of the C array is required for the Sigma part. The formula for a [0] And a [n + 1] to obtain a [1] can be simplified.

Therefore, the idea is to create a stacked sub-operator to separate the two sides of the equation.


Code(Ac ):

# Include <cstdio> # include <cstring> # include <iostream> using namespace STD; # define maxn 3002 double C [maxn]; int N; double solve (double A0, double an1) {double T = 0; For (INT I = 1; I <= N; I ++) {C [I] + = C [I-1]; T + = C [I];} double ret = N * A0 + an1-2 * t; return ret/(double) (n + 1);} int main () {int t; scanf ("% d", & T); While (t --) {double A0, an1; scanf ("% d", & N ); scanf ("% lf", & A0, & an1); For (INT I = 1; I <= N; I ++) {scanf ("% lf ", & C [I]);} double ans = solve (A0, an1); printf ("%. 2lf \ n ", ANS); 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.