Codeforce 712A Memory and Crow
来源:互联网 发布:淘宝运营助理面试技巧 编辑:程序博客网 时间:2024/05/13 19:04
There are n integers b1, b2, ..., bn written in a row. For alli from 1 to n, values ai are defined by the crows performing the following procedure:
- The crow sets ai initially0.
- The crow then adds bi toai, subtractsbi + 1, adds thebi + 2 number, and so on until then'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 numbersb1, b2, ..., bn written in the row? Can you do it?
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.
Print n integers corresponding to the sequenceb1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.
5
6 -4 8 -2 3
2 4 6 1 3
5
3 -2 -1 5 6
1 -3 4 11 6
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and3 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
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n,a,b; 6 while(cin>>n) 7 { 8 for(int i=1;i<=n;i++) 9 {10 cin>>a;11 if(i>1)12 cout<<a+b<<" ";13 b=a;14 }15 cout<<a<<endl;16 }17 return 0;18 }
- Codeforce 712A Memory and Crow
- Codeforce 712A Memory and Crow
- Codeforce 712A Memory and Crow
- Codeforce 712A Memory and Crow
- A. Memory and Crow
- Codeforces Problem 712A Memory and Crow
- Codeforces-712A-Memory and Crow
- Codeforces 712A Memory and Crow 水题
- codeforces A. Memory and Crow
- Codeforces Problem 712A Memory and Crow(公式推导)
- CodeForces 712A. Memory and Crow(水题)
- 【Codeforces Round 370 (Div 2) A】【水题】Memory and Crow
- Codeforces #370(Div.2) A.Memory and Crow【水题】
- Codeforce - 712 -C. Memory and De-Evolution
- codeforce A. Pasha and Pixels
- codeforce A. Alyona and Numbers
- codeforce-【A. Dima and Guards】
- 【codeforce】A. Anastasia and pebbles
- qsort函数、sort函数 (精心整理篇)(转载)
- 郑重之场合行事易紧张,怎么办?
- uml总结
- 《劝学》与程序
- linux驱动-I/O
- Codeforce 712A Memory and Crow
- 数字图像学习一之点运算
- jni和ndk区别
- 【JSOI2015】【JZOJ 4058】子集选取
- virtualbox linux虚拟机桥接模式
- 152. Maximum Product Subarray -Medium
- 使用Sublime Text3的心得体会——遇到标题处的中文显示方框怎么办
- Mathematics
- LabVIEW用Grab连续采集图像的完整过程