HDU 2086 A1 = ?(规律)

A1 = ?

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5932    Accepted Submission(s): 3721


Problem Description
有如下方程:A i = (A i-1 + A i+1)/2 - C i (i = 1, 2, 3, .... n).
若给出A 0, A n+1, 和 C 1, C 2, .....C n.
请编程计算A 1 = ?
 

Input
输入包括多个测试实例。
对于每个实例,首先是一个正整数n,(n <= 3000); 然后是2个数a 0, a n+1.接下来的n行每行有一个数c i(i = 1, ....n);输入以文件结束符结束。
 

Output
对于每个测试实例,用一行输出所求得的a1(保留2位小数).
 

Sample Input
   
   
   
   
1 50.00 25.00 10.00 2 50.00 25.00 10.00 20.00
 

Sample Output
   
   
   
   
27.50 15.00
 

Source
2006/1/15 ACM程序设计期末考试
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   2082  2080  2094  2089  2076


n=1;2A1=A0+A2-2C1
n=2;3A1=2A0+A3-4C1-2C2
n=3;4A1=3A0+A4-6C1-4C2-2C3
n=5;5A1=4A0+A5-8C1-6C2-4C3-2C4;
 
#include<stdio.h>
int main(){
    double a0,a1,ai,c[3010];
    int n;
    while(~scanf("%d",&n)){
        scanf("%lf%lf",&a0,&ai);
        a1=n*a0+ai;
        int k=n;
        for(int i=1;i<=n;i++){
            scanf("%lf",&c[i]);
            a1=a1-k*2*c[i];
            k--;
        }
        printf("%.2lf\n",a1/(n+1));
    }
    return 0;
}


你可能感兴趣的:(HDU)