poj2601(变形的等差数列求单项)

http://poj.org/problem?id=2601

Simple calculations
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 6084Accepted: 3085

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.

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

题意: 公式ai = (ai-1 + ai+1)/2 - ci已知a0,an+1,和ci(i=1~~n),求a1..。。

数学题推吧。终于推出来了,这种题高中生比大学生做的快多了。。

ai = (ai-1 + ai+1)/2 - ci

2*ai=(ai-1+ai+1)/2-2*ci;

得到:2*a1=a0+a2-2c1;

      2*a2=a1+a3-2*c2;

      2*a3=a2+a4-2*c3;

     ……………………

     ……………………

      2*an=an-1+an+1-2*cn;

左右累加得到

an+a1=an+1+a0-2*(c1+c2++++++………………cn);

得到

a1-a0=an+1-an-2(c1+c2+…………cn);

得到

a1-a0=an+1-an-2(c1+++cn);

a1-a0=an-an-1-2(c1+c2+…………cn-1);

a1-a0=an-1-an-2-2*(c1++++++++cn-2);

左右相加得到

a1=((an+1+n*a0)-2n*(c1)+2*(n-1)*c2+++++…………2*1*cn)/(n+1);

#include
#include
#include
using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        double a0,ak,c;
        double sum=0;
        scanf("%lf%lf",&a0,&ak);
        for(int i=n;i>=1;i--)
        {
            scanf("%lf",&c);
            sum-=2*i*c;
        }
        //sum=-sum;
        sum+=(ak+n*a0);
        printf("%.2lf\n",sum/(n+1));
    }
    return 0;
}

 

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值