A1 =?

Source: Internet
Author: User

A1 =?Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 5116 Accepted Submission (s): 3265

problem Descriptionthere are the following equations: Ai = (Ai-1 + ai+1)/2-ci (i = 1, 2, 3, .... n).
If given A0, an+1, and C1, C2, ..... Cn.
Please program calculate A1 =?
InputThe input includes 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.

Outputfor each test instance, a row is used to output the calculated A1 (retain 2 decimal places).
Sample Input
150.0025.0010.00250.0025.0010.0020.00

Sample Output
27.5015.00Problem Solving Ideas:Pure math problem, find the law: an = (An-1) + (an+1-cnan-1) = (2/3) An-2 + (1/3) an+1-(2/3) Cn-(4/3) cn-1an-2 = (3/4) An-3 + (quarter) an+1- (1/2) Cn-cn-1-(3/2) cn-2an-3 = (4/5) An-4 + (1/5) an+1-(2/5) Cn-(4/5) Cn-1-(6/5) Cn-2-(8/5) Cn-3 ...  (Does it feel a little bit) then: A1 = (n/(n+1)) A0 + (1/(n+1)) an+1-(2/(n+1)) Cn-(4/(n+1)) Cn-1-...-(2n/(n+1)) C1 = [nA0 + an+1-2 (Cn + 2cn-1 + 3cn-2 + ... + nC1)]/(n+1)Source code:#include <stdio.h> #include <stdlib.h> #define MaxSize 3001int Main () {int i,n;  Double a1,a0,end;   Double c[maxsize];    while (scanf ("%d", &n)!=eof) {scanf ("%lf%lf", &a0,&end);    for (i=0;i<n;i++) scanf ("%lf", &c[i]);    A1 = n A0 + end;     for (i=0;i<n;i++) a1-=2* (i+1) *c[n-1-i];    A1 =a1/(1 + N);  printf ("%.2lf\n", A1);  } system ("Pause"); return 0;} 

A1 =?

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.