Freshman race 1011 Singles Day gift of the world

Source: Internet
Author: User

Topic:

Now, 11.11 in college life is a special day, many schools have it as a boy's day, as a sister, LPT also want to give the younger brother, but so much, how to send? So she thought of an idea,
Can out a math problem exam, the first three AC this problem of the younger brother can get small gifts!
There is a set of sequences, it has n+2 elements, a[0],a[1], ..., a[n+1] (n <=, -10000 <= a[i]<=10000), for i = 1,2,3,...,n satisfies a[i]-c[i]= (a[i-1]+a [I+1]) /2-b[i],
If given a[0],a[n+1] and the values of all elements of set B, C (i.e. given b[1],b[2]...b[n] and c[1],c[2],..., c[n],-100≤b[i], c[i]≤100), are reserved for the two digits after the decimal point, the Smart
Can you figure out a[1]?

Ideas:

      first, constant items can be combined, ci=  (ai+1"/2 −  with - ci bashi sub-formation:   < Span class= ">aaa

variants: a -  -  =   -         

      Then, i  1 start, to i   n

a  " a1 2   

A3 - a2 - 2d2 = a2 - A 1

···

An+1 - an - 2dn = an - an-1

Add the n to get

 a0 -< Span class= "> a1 + n+1n * $ \sum_{i=1}^{n}d_i$< Span class= ">= 0        (

by formula (1) available

An+1 - an - 2dN= an - an-1

2                      

a0 - 1nn-12 * $ \sum_{i=1}^{n-1}d_i$ =     (

Repeat , get:

A0 - a1 + a2 - a1 - 2 d1 = 0 (n+1)

The formula (2) is added to the formula (n+1)to:

A1=(n*A0+AN+1-2* * 1  -2 *     2dn

Code:

1#include <cstdio>2 intMain ()3 {4     //freopen ("Data_in.txt", "R", stdin);5     //freopen ("Data_out.txt", "w", stdout);6     intN, I, T;7     DoubleA1, X, Y, b[3010], c[3010], d[3010], sum=0.0;8scanf"%d", &T);9      while(t--)Ten     { Onescanf"%d", &n); Ascanf"%LF%LF", &x, &y); -          for(i =1; I <= N; i++) -         { thescanf"%LF", &b[i]); -         } -          for(i =1; I <= N; i++) -         { +scanf"%LF", &c[i]); -D[i] = b[i]-C[i]; +         } A          for(i =1; I <= N; i++) at         { -Sum + =2* (N-i +1) *D[i]; -         } -A1 = (n * x-sum + y)/(n +1); -printf"%.2lf\n", A1); -     } in  -     return 0; to}
AC Code

Freshman race 1011 Singles Day gift of the world

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.