Codeforces Round #370 (Div. 2) 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?
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 sequence b1, 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, 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.
题意:告诉你 ai = bi - bi + 1 + bi + 2 - bi + 3 ,和b的序列,求a的序列
解法:反过来就好了,会发现规律都是相加
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int n,m;
int b[100005];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
int cot=1;
a[n+1]=0;
for(int i=n;i>=1;i--)
{
b[cot++]=a[i+1]+a[i];
}
for(int i=cot-1;i>=1;i--)
{
cout<<b[i]<<endl;
}
return 0;
}
Codeforces Round #370 (Div. 2) A的更多相关文章
- Codeforces Round #370 (Div. 2) E. Memory and Casinos (数学&&概率&&线段树)
题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操 ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos 线段树
E. Memory and Casinos 题目连接: http://codeforces.com/contest/712/problem/E Description There are n casi ...
- Codeforces Round #370 (Div. 2)C. Memory and De-Evolution 贪心
地址:http://codeforces.com/problemset/problem/712/C 题目: C. Memory and De-Evolution time limit per test ...
- Codeforces Round #370 (Div. 2)B. Memory and Trident
地址:http://codeforces.com/problemset/problem/712/B 题目: B. Memory and Trident time limit per test 2 se ...
- Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划
D. Memory and Scores 题目连接: http://codeforces.com/contest/712/problem/D Description Memory and his fr ...
- 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 #370 (Div. 2) A. Memory and Crow 水题
A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...
- Codeforces Round #370(div 2)
A B C :=w= D:两个人得分互不影响很关键 一种是f[i][j]表示前i轮,分差为j的方案数 明显有f[i][j]=f[i-1][j-2k]+2*f[i-1][j-2k+1]+...+(2k+ ...
- Codeforces Round #370 (Div. 2)(简单逻辑,比较水)
C. Memory and De-Evolution time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- csu oj 1339: 最后一滴血
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1339 1339: 最后一滴血 Time Limit: 1 Sec Memory Limit: 1 ...
- java正则表达式练习
package shb.java.demo3; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * 正则表达式简 ...
- CSS3 Transform Matrix
css3中的transform让我们操作变形变得很简单,诸如,translate–移动,scale–缩放,rotate–旋转,skew–斜切.这几个属性很方便,也很简单,但是其中matrix我们就不常 ...
- haskell笔记2
模式匹配 # haskell_test.hs length' :: [a] -> a length' [] = 0 length' (_:x) = 1 + length' x as模式 xs@x ...
- 转:V$SQL,V$SQLAREA,V$SQLTEXT
V$SQL*表用于查看Shared SQL Area中SQL情况 V$SQLTEXT V$SQLTEXT用途很简单,就是用来查看完整的SQL语句,V$SQL和V$SQLAREA只能显示1000 byt ...
- 【py网页】urlopen的补充,完美
urllib 是 python 自带的一个抓取网页信息一个接口,他最主要的方法是 urlopen(),是基于 python 的 open() 方法的.下面是主要说明: 1 urllib.urlopen ...
- 学习K&R时初学者经常遇到的一个问题——EOF
学习K&R时初学者经常遇到的一个问题——EOF
- C语言初学者代码中的常见错误与瑕疵(4)
问题 小学生数学 很多小学生在学习加法时,发现“进位”特别容易出错.你的任务是计算两个数在相加时需要多少次进位.你编制的程序应当可以连续处理多组数据,直到读到两个0(这是输入结束标记). 样例: 输入 ...
- HGE引擎之hgeSprite
一.hgeSprite类 hgeSprite是一个精灵实体的HGE帮助类. 1.构造函数 创建和初始化一个hgeSprite对象. hgeSprite(HTEXTURE tex, float x, f ...
- OpenStack 的windows镜像的开启办法
创建虚拟机 使用我们的管理平台的windows主机创建流程,创建一台主机.在vnc中能看到主机进入到系统中 需要点击按钮sendctrl进入输入密码阶段. 输入我们的镜像的默认密码:5@mdjkw 打 ...