A. Memory and Crow
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:

  • The crow sets ai initially 0.
  • The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3....

Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row.

The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

Output

Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

Examples
Input
5
6 -4 8 -2 3
Output
2 4 6 1 3 
Input
5
3 -2 -1 5 6
Output
1 -3 4 11 6 
Note

In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.

In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

解题思路:

【题意】
有n个数b1, b2, ..., bn

a1, a2, ..., an是通过等式ai = bi - bi + 1 + bi + 2 - bi + 3....(±)bn得到的

现给你a1, a2, ..., an这n个数,问b1, b2, ..., bn是多少
【类型】
公式推导
【分析】

由此可见,数组b中的第i项等于数组a中的第i项与第i+1项之和

特别地,数组b中的第n项等于数组a中的第n项

【时间复杂度&&优化】
O(n)

题目链接→Codeforces Problem 712A Memory and Crow

 #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b;
while(cin>>n)
{
for(int i=;i<=n;i++)
{
cin>>a;
if(i>)
cout<<a+b<<" ";
b=a;
}
cout<<a<<endl;
}
return ;
}

Codeforce 712A Memory and Crow的更多相关文章

  1. codeforces 712A. Memory and Crow

    题目链接:http://codeforces.com/problemset/problem/712/A 题目大意: 给你一个数字系列,求其满足条件的一个序列. 条件为: ai = bi - bi +  ...

  2. CodeForces 712A Memory and Crow (水题)

    题意:有一个序列,然后对每一个进行ai = bi - bi + 1 + bi + 2 - bi + 3.... 的操作,最后得到了a 序列,给定 a 序列,求原序列. 析:很容易看出来,bi = ai ...

  3. codeforces 712A A. Memory and Crow(水题)

    题目链接: A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  4. Codeforces Round #370 (Div. 2) A. Memory and Crow 水题

    A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...

  5. codeforces 712A. Memory and Crow

    2019-05-18 08:48:27 加油,加油,坚持!!! 这道题我没有想出公式推导,只是按照模拟题来做,第5个样例超时 样例超时,方法错误 https://www.cnblogs.com/ECJ ...

  6. ECJTUACM16 Winter vacation training #4 题解&源码

    A......................................................................................... 题目链接→Code ...

  7. CSUST 8.4 早训

    ## Problem A A - Memory and Crow CodeForces - 712A 题意: 分析可得bi=ai+ai+1 题解: 分析可得bi=ai+ai+1 C++版本一 #inc ...

  8. Codeforces Round #370 - #379 (Div. 2)

    题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi  ...

  9. Codeforces Round #370 (Div. 2) A B C 水 模拟 贪心

    A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. centos7中yum安装ntfs-3g

    CentOS默认源里没有ntfs3g,想要添加ntfs支持,无非是自己下载编译安装或者加源yum安装. 新安装了一个CentOS7,用的是添加aliyun的epel源来yum安装的方式,简单易行. 1 ...

  2. axis2开发实例(二)建立独自的新工程

    第一部分 环境搭建 1.  环境搭建 (1)    下载Axis2服务包:axis2-1.6.2-bin.zip,axis2-1.6.2-war.zip,分别解压到D:\webservice_axis ...

  3. lpc1768的系统时钟

    #define XTAL_FREQ   12000000 #define VECT_TAB_OFFSET  0x0000 void SystemInit(void) { //PLL0时钟配置 LPC_ ...

  4. AFNetworking3.0为何弃用了NSURLConnection

    http://blog.csdn.net/qq_34101611/article/details/51698524 上篇博客说到AFNetworking3.0只提供了NSURLSession的支持.其 ...

  5. virtio-win 驱动

    Direct downloads are available for the .iso, .vfd, and qemu-ga installers. Stable virtio-win iso: ht ...

  6. iOS开发——工厂模式

    工厂模式很好用,为表诚意,我直接搞个实用的例子放这,解析一个订单的数据,并且这个订单里面可能不止一件商品的做法. 还是直接上代码,不懂的地方,再提出来. 1.在MyOrderDeals.h文件中 #i ...

  7. Eclipse上Spring-tool的安装

    三种安装方式: 插件地址:http://spring.io/tools/sts/all 1.在线安装  Help-->> Install new Software 2.本地安装,Help- ...

  8. IOS开发中数据持久化的几种方法--NSUserDefaults

    IOS开发中数据持久化的几种方法--NSUserDefaults IOS 开发中,经常会遇到需要把一些数据保存在本地的情况,那么这个时候我们有以下几种可以选择的方案: 一.使用NSUserDefaul ...

  9. nginx代理tomcat后,tomcat获取真实(非proxy,非别名)nginx服务端ip端口的解决方案

    nginx代理tomcat后,tomcat获取服务端ip端口的解决方案 1.注意修改nginx配置代理,标红地方 #user nginx; worker_processes ; error_log l ...

  10. 2781: [JSOI2007]文本生成器

    2781: [JSOI2007]文本生成器 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 8  Solved: 4[Submit][Status][We ...