CodeForces 712A. Memory and Crow(水题)
2016-12-07 19:51
218 查看
A. Memory and Crow
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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个ai,ai = bi - bi + 1 + bi + 2 - bi + 3….求出bi
思路:其实ai-bi=ai+1,解个方程求出bi就可以了,最后一个bi和ai相等。
代码
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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个ai,ai = bi - bi + 1 + bi + 2 - bi + 3….求出bi
思路:其实ai-bi=ai+1,解个方程求出bi就可以了,最后一个bi和ai相等。
代码
#include<stdio.h> #include<iostream> #include<algorithm> #include<math.h> #include<string.h> using namespace std; const int maxn=100005; long long int num[maxn]; int main() { int N; scanf("%d",&N); for(int i=0;i<N;i++) scanf("%I64d",&num[i]); for(int i=0;i<N-1;i++) printf("%I64d ",num[i]+num[i+1]); printf("%I64d\n",num[N-1]); return 0; }
相关文章推荐
- CodeForces 474A Keyboard (水题)
- 【打CF,学算法——一星级】Codeforces 699A Launch of Collider (水题)
- codeforces水题100道 第八题 Codeforces Round #274 (Div. 2) A. Expression (math)
- codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)
- Codeforces 432A Choosing Teams(水题)
- codeforces 136A Presents(水题)
- Codeforces 635A Orchestra 【水题】
- CodeForces 66B - Petya and Countryside(水题)
- Codeforces 868A Bark to Unlock 水题
- codeforces 557B Pasha and Tea-水题
- Codeforces 454A Little Pony and Crystal Mine(水题)
- codeforces 637D D. Running with Obstacles(dp,水题,贪心)
- CodeForces 300A Array(水题)
- Codeforces--366A--Dima and Guards(水题)
- Codeforces 652A Gabriel and Caterpillar【水题】
- codeforces 659B B. Qualifying Contest(水题+sort)
- CodeForces - 682B 题意水题
- CodeForces水题
- codeforces 664A A. Complicated GCD(水题)
- CodeForces 165A Supercentral Point(水题)