Codeforces Round #370 (Div. 2) A. Memory and Crow 水题
2016-09-13 11:19
731 查看
A. Memory and Crow
题目连接:
http://codeforces.com/contest/712/problem/ADescription
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
56 -4 8 -2 3
Sample Output
2 4 6 1 3Hint
题意
题解:
显然知道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) D.Memory and Scores 【前缀和 DP】双人随机数值增减K A比B多的方案数
- 【Codeforces Round 370 (Div 2) D】【前缀和打标记】Memory and Scores 双人随机数值增减K A比B多的方案数
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution【逆向思维+贪心】
- 【Codeforces Round 370 (Div 2) E】【线段树 等比数列 区间合并】Memory and Casinos 赌场区间[l,r] l进r先出的概率
- Codeforces Round #370 (Div. 2) D. Memory and Scores(DP)
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution【dfs+想法】
- 【Codeforces Round 370 (Div 2) B】【简单贪心】Memory and Trident
- Codeforces Round #370 (Div. 2) E. Memory and Casinos 线段树
- 【Codeforces Round 370 (Div 2) C】【正难则反 贪心】Memory and De-Evolution
- 【Codeforces Round 262 (Div 2)A】【水题】Vasya and Socks 妈妈买袜子 最多穿几天
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
- Codeforces Round #365 (Div. 2) 703B Mishka and trip 水题
- Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
- 【Codeforces Round 263 (Div 2)A】【水题 认真读题】Appleman and Easy Task 每个点的相邻o是否都为偶数
- 【Codeforces Round 331 (Div 2)A】【水题】Wilbur and Swimming Pool 给出矩形1~4个顶点让你还原矩形
- Codeforces Round #384 (Div. 2) A. Vladik and flights【思维】水题
- 【Codeforces Round 263 (Div 2)B】【水题 贪心】Appleman and Card Game 选字符,每个字符个数的平方
- 【Codeforces Round 332 (Div 2)A】【水题】A. Patrick and Shopping 遍历三元环的最小成本
- 【Codeforces Round 331 (Div 2)B】【水题 贪心】Wilbur and Array 修改对p位置后的所有位置生效 最少修改次数使得数列变成b