Simple calculations
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6559   Accepted: 3291

Description

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.

Input

The first line of an input 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

The output file should contain a1 in the same format as a0 and an+1.

Sample Input

1
50.50
25.50
10.15

Sample Output

27.85

解题思路:

大概过程:
a[0]+a[2]-2a[1]-2c[1]=0
a[1]+a[3]-2a[2]-2c[2]=0
……
a[n-1] + a[n+1] - 2a[n] - 2c[n] = 0
累加可得:
a[0]+a[n+1]-a[1]-a[n]-2c[1]-2c[2]-...-2c[n]=0
依据a[n-1]+a[n+1]-2a[n]-2c[n]=0 => a[n+1]-2c[n]-a[n]=a[n]+2c[n]-a[n-1]
化简:a[0]+a[n]-a[1]-a[n-1]-2c[1]-2c[2]-...-2c[n-1]=0
同理:a[0]+a[n-1]-a[1]-a[n-2]-2c[1]-2c[2]-...-2c[n-2]=0
……
a[0]+a[2]-a[1]-a[1]-2c[1]=0
相加上面各式可得n*a[0]+a[n+1]-(n+1)*a[1]-2*n*c[1]-2*(n-1)*c[2]-...-2*c[n]=0
即a[1]=(n*a[0]+a[n+1]-2*n*c[1]-2*(n-1)*c[2]-...-2*c[n])/(n+1)
#include <iostream>
#include <iomanip>
using namespace std;
#define MAX 3005
int main(){
int n;
double a0,an;
double c[MAX];
while (cin>>n){
cin>>a0>>an;
double ans=0;
for (int i=0;i<n;i++){
cin>>c[i];
ans+=2*(n-i)*c[i];
}
ans=(n*a0+an-ans)/(n+1);
cout<<fixed<<setprecision(2)<<ans<<endl;
}
return 0;
}

poj 2601 Simple calculations的更多相关文章

  1. 【POJ】【2601】Simple calculations

    推公式/二分法 好题! 题解:http://blog.csdn.net/zck921031/article/details/7690288 这题明显是一个方程组……可以推公式推出来…… 然而这太繁琐了 ...

  2. UVA - 10014 - Simple calculations (经典的数学推导题!!)

    UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...

  3. Poj 3468-A Simple Problem with Integers 线段树,树状数组

    题目:http://poj.org/problem?id=3468   A Simple Problem with Integers Time Limit: 5000MS   Memory Limit ...

  4. POJ A Simple Problem with Integers 线段树 lazy-target 区间跟新

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 105742 ...

  5. POJ 3468A Simple Problem with Integers(线段树区间更新)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 112228 ...

  6. POJ 3922A Simple Stone Game

    题目链接 A Sample Stone Game 题目大意:给定n,k,表示最初时有n个石头,两个人玩取石子游戏,第一个人第一次可以取1~n-1个石头,后面每个人最多可以拿走前面一个人拿走的个数的K倍 ...

  7. uva 10014 Simple calculations

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. POJ 2601

    #include<iostream> #include<iomanip> #include<stdio.h> using namespace std; int ma ...

  9. POJ - 3468A Simple Problem with Integers (线段树区间更新,区间查询和)

    You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...

随机推荐

  1. Linux命令之crontab

    crontab [-u user] file crontab [-u user] [-l | -r | -e] [-i] [-s] crontab命令被用来提交和管理用户需要周期性执行的任务,与win ...

  2. 基于 Python + OpenCV 进行人脸识别,视频追踪代码全注释

    先来普及一下概念, 计算机对人脸是如何识别的呢? 或者说图像是如何识别的.主要是获取单张图片的特征值记录了特征值以后,如果下一张图片来了以后两张图片特征值进行对比,如果相似度很高那么计算机就认定这两个 ...

  3. 洛谷 P4173 残缺的字符串

    (不知道xjb KMP可不可以做的说) (假设下标都以0开头) 对于有一定偏移量的序列的 对应位置 匹配或者数值计算的题,这里是有一种套路的,就是把其中一个序列翻转过来,然后卷积一下,所得到的新序列C ...

  4. 【贪心】【线性基】bzoj2460 [BeiJing2011]元素 / bzoj3105 [cqoi2013]新Nim游戏

    p2460: #include<cstdio> #include<algorithm> using namespace std; #define N 1001 typedef ...

  5. 5.2类集(java学习笔记)Map,Set接口

    一.Map接口 Map接口中存储数据是通过key->value的方式成对存储的,可以通过key找到value. 二.Map接口常用子类 1.HashMap HashMap是无序存放的,key不允 ...

  6. BUG YII2.0 cURL error 6: Could not resolve host:

    BUG描述:登录直接显示 原因:服务器设置端口权限,或者DNS毛病 解决方案:只能去服务器端设置,配置端口 DNS: 修改dns 114.114.114.114 或者 8.8.8.8

  7. 使用FluentValidation来进行数据有效性验证

    之前我介绍过了使用系统自带的Data Annotations来进行数据有效性验证,今天在CodePlex上逛的时候,发现了一个非常简洁好用的库:FluentValidation 由于非常简洁,就直接拿 ...

  8. HTTP Basic 验证客户端 C#实现笔记

    HTTP Basic 验证客户端的原理:把HTTP头重的ContentType设置为:application/x-www-form-urlencoded如果HTTP头没有Authorization,那 ...

  9. Linux 命令缩写部分解释

    转:http://blog.chinaunix.net/uid-28408358-id-3890783.html bin = BINaries  /dev = DEVices  /etc = ETCe ...

  10. git rebase、git merge、git cherry-pick 使用详解

    1.git cherry-pick 是合入其他分支的某一次或者几次提交(cherry-pick是挑选的意思):把其他分支的某些功能合入当前分支 2.git merge 把其他分支合入当前分支,一般用作 ...