Codeforces Problem 712A Memory and Crow
2016-09-19 19:12
344 查看
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
Input
Output
Input
Output
Sample Output
Hint
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.
#include<iostream>
using namespace std;
const int N=100100;
int main()
{
long long arr
;
int n;
cin >> n;
for(int i=0; i<n; i++)
{
cin >> arr[i];
}
for(int i=1; i<n; i++)
{
cout << arr[i]+arr[i-1] << " ";
}
cout << arr[n-1];
return 0;
}
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
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
Sample Output
Hint
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.
#include<iostream>
using namespace std;
const int N=100100;
int main()
{
long long arr
;
int n;
cin >> n;
for(int i=0; i<n; i++)
{
cin >> arr[i];
}
for(int i=1; i<n; i++)
{
cout << arr[i]+arr[i-1] << " ";
}
cout << arr[n-1];
return 0;
}
相关文章推荐
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
- Codeforces Round #400 D. The Door Problem(2-sat)
- Arpa’s obvious problem and Mehrdad’s terrible solution CodeForces - 742B (异或)
- codeforces Educational Codeforces Round 41 (Rated for Div. 2) for B problem
- Educational Codeforces Round 46 (Rated for Div. 2) D. Yet Another Problem On a Subsequence
- Codeforces Round #FF (Div. 2) Problem A DZY Loves Hash
- Codeforces Round #211 (Div. 2), problem: (A) Soroban,problem: (B) Fence,problem: (C)
- Codeforces Round #410 (Div. 2) Mike and gcd problem 思维
- Codeforces Round #410 (Div.2) C.Mike and gcd problem-数学
- Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- Codeforces #270 D. Design Tutorial: Inverse the Problem
- Educational Codeforces Round 29-D-Yet Another Array Queries Problem(瞎搞)
- Codeforces Problem 332C - Student's Revenge(未A)
- Codeforces Round #253 (Div. 2), problem: (B)【字符串匹配】
- Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - B. Color the Fence 【贪心】
- Design Tutorial: Inverse the Problem CodeForces - 472D 最小生成树,好题目
- Codeforces Problem 598E - Chocolate Bar
- AC日记——Little Elephant and Problem codeforces 221c