Ural 1047 Simple calculations

1047. Simple calculations

Time Limit: 1.0 second
Memory Limit: 16 MB
There is a sequence of N + 2 elements a0, a1, …, aN+1 (1 ≤ N ≤ 3000, −2000 ≤ ai ≤ 2000). 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.

Input

The first line contains an integer N. The next two lines consist of numbers a0 and aN+1 each having two digits after decimal point, and the next N lines contain numbers ci (also with two digits after decimal point), one number per line.

Output

Output a1 in the same format as a0 and aN+1.

Sample

input output
1
                        50.50
                        25.50
                        10.15
                        
27.85
                        
Problem Author: Dmitry Filimonenkov
Problem Source: Ural State University collegiate programming contest (25.03.2000)

   用数学方法推出公式即可:
     
 
//ural1047
//a1=( aN_1 +N*a0 -2*( (c1+……cN)+ (c1+……cN-1 ) +……(c1+c2)+(c1) ))/(N+1)
#include<iostream>
using namespace std;
double ci[3010]={0};  //ci[i]=c1+c2+……ci
int main()
{
   
int N,i;
   
double a0,aN_1,temp,sum=0;
   cin
>>N>>a0>>aN_1;
   
for(i=1; i<=N; i++)
   {
       cin
>>temp; 
       ci[i]
=ci[i-1]+temp;
       sum
+=ci[i];
   }

   sum
*=2;

   cout.precision(
2);
   cout
<<fixed<<( aN_1+ N*a0 -sum)/(N+1)<<endl;

   system(
"pause");
    
return 0;
}

posted on 2010-06-24 23:09 田兵 阅读(167) 评论(0)  编辑 收藏 引用 所属分类: URAL


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年6月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

常用链接

留言簿(2)

随笔分类(65)

随笔档案(65)

文章档案(2)

ACM

搜索

积分与排名

最新随笔

最新评论

阅读排行榜