纯公式推导。。。,不谢。。
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.
Each test case will be separated by a single line.
The Output
For each test case, the output file should 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <string.h>
int main()
{
int t, n, i, j, k;
double a, b, s[3004], x, y;
scanf("%d",&t);
for(i = 0; i < t; i++)
{
x = 0;
memset(s,0,sizeof(s));
scanf("%d%lf%lf", &n, &a, &b);
for(j = 1; j <= n; j++)
{
scanf("%lf", &s[j]);
y = 0;
for(k = 1; k <= j; k++)
{
y = y + s[k];
}
x = x + y;
}
printf("%.2lf\n", (n*a+b-2*x)/(n+1));
if(i != t-1)
printf("\n");
}
return 0;
}