poj 2601 Simple calculations

it2024-04-16  13

Simple calculations Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5803 Accepted: 2947

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 - cifor each i=1, 2, ..., n. 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 #include <iostream>using namespace std;int main(){ int n,i; double a,b,temp; double sum=0.0; scanf("%d",&n); scanf("%lf%lf",&a,&b); for (i=0;i<n;i++) { scanf("%lf",&temp); sum+=(n-i)*temp; } sum=-sum*2; sum+=n*a+b; sum/=n+1; printf("%.2lf\n",sum); return 0;}

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/22/2258609.html

相关资源:数据结构—成绩单生成器
最新回复(0)