Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6934 | Accepted: 3442 |
Description
There is a sequence of n+2 elements a
0, a
1, ..., a
n+1
(n <= 3000, -1000 <= a
i <=1000). It is known that
ai = (ai-1 + ai+1)/2 - ci for each i=1, 2, ..., n.
You are given a 0, a n+1, c 1, ... , c n. Write a program which calculates a 1.
You are given a 0, a n+1, c 1, ... , c n. Write a program which calculates a 1.
Input
The first line of an input contains an integer n. The next two lines consist of numbers a
0
and a
n+1
each having two digits after decimal point, and the next n lines contain numbers c
i(also with two digits after decimal point), one number per line.
Output
The output file should contain a
1
in the same format as a
0
and a
n+1.
Sample Input
1 50.50 25.50 10.15
Sample Output
27.85
Source
问题链接:POJ2601 Simple calculations
问题简述:(略)
问题分析: 数列计算问题。
先进行数列通项公式的推导,然后再套公式计算,事情就简单了。
程序说明:本题与参考链接的题是同一个问题,输入输出格式不同。
题记:数学问题通常是先进行数学推导,再按照数学公式做计算。
参考链接:UVA10014 Simple calculations
/* POJ2601 Simple calculations */
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n;
double a, b, sum = 0;
while(~scanf("%d", &n)) {
scanf("%lf%lf", &a, &b);
for(int i=0; i<n; i++) {
double x;
scanf("%lf", &x);
sum += (n - i) * x;
}
printf("%.2f\n", (n * a + b - 2 * sum) / (n + 1.0));
}
return 0;
}