Codeforces Round #370 (Div. 2) A. Memory and Crow 水题
A. Memory and Crow
题目连接:
http://codeforces.com/contest/712/problem/A
Description
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.
Sample Input
5
6 -4 8 -2 3
Sample Output
2 4 6 1 3
Hint
题意
题解:
显然知道an=bn,然后剩下的可以手动推一下公式,就可以递推出来了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int a[maxn],n;
long long b[maxn];
int main()
{
scanf("%d",&n);
long long sum = 0;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=n;i>=1;i--)
{
sum*=-1;
b[i]=a[i]-sum;
sum+=b[i];
}
for(int i=1;i<=n;i++)
printf("%lld ",b[i]);
printf("\n");
}
Codeforces Round #370 (Div. 2) A. Memory and Crow 水题的更多相关文章
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution 水题
C. Memory and De-Evolution 题目连接: http://codeforces.com/contest/712/problem/C Description Memory is n ...
- Codeforces Round #370 (Div. 2) B. Memory and Trident 水题
B. Memory and Trident 题目连接: http://codeforces.com/contest/712/problem/B Description Memory is perfor ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
随机推荐
- Mysql MERGE引擎简介
一. 什么是MERGE引擎MERGE存储引擎把一组MyISAM数据表当做一个逻辑单元来对待,让我们可以同时对他们进行查询. 二. 应用场景如果需要把日志纪录不停的录入MySQL数据库,并且每天.每周或 ...
- ubuntu 下没有pthread库以及报undefined reference to 'pthread_create'的解决方法
https://blog.csdn.net/dyzhen/article/details/79058554
- 20155215 2016-2017-2 《Java程序设计》第7周学习总结
20155215 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 第十二章 lambda语法:Lambda去重复,回忆DRY原则,Lambda表达式可读性更好 ...
- [CEOI2015 Day2]世界冰球锦标赛 (双向搜索)
题目描述 [CEOI2015 Day2]世界冰球锦标赛译自 CEOI2015 Day2 T1「Ice Hockey World Championship」 今年的世界冰球锦标赛在捷克举行.Bobek ...
- ZYNQ. Interrupt(1)Private Timer
Interrupt zynq的中断. The PS is based on ARM architecture, utilizing two Cortex-A9 processors(CPUs) and ...
- 初识 Asp.Net数据验证控件
在我们建立一个Asp.Net Web应用程序的时候我一般都会注意我们工具如图
- OS X 10.11:如何完全停用Time Machine。
家里的2010年21.5英寸iMac越来越慢,用HFS+分区的1.5TB外置硬盘进行备份时,100G数据经常两三个小时还不能备份完.Time Machine虽然方便,但效率太低,不得不停用. 1. 要 ...
- python爬虫-基础
所谓网页抓取,就是把URL地址中指定的网络资源从网络流中读取出来,保存到本地. 类似于使用程序模拟IE浏览器的功能,把URL作为HTTP请求的内容发送到服务器端, 然后读取服务器端的响应资源. 1.浏 ...
- KnockoutJs学习笔记(六)
这篇文章主要涉及control flow部分的binding. foreach binding主要作用于lists或是tables内数据单元的动态绑定.下面是一个简单的例子: js部分: ko.app ...
- ***Bootstrap FileInput插件的使用经验汇总
插件下载地址: https://github.com/kartik-v/bootstrap-fileinput/ 官方DEMO查看: http://plugins.krajee.com/file-ba ...