题目描述:
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
5
6 -4 8 -2 3
2 4 6 1 3

5
3 -2 -1 5 6
1 -3 4 11 6

题目描述:
有两个数组,一个数组为a,一个为b ,在给你一个数n,和数组啊,我们要求出数组b的每个元素,并且我们知道ai = bi - bi + 1 + bi + 2 - bi + 3…
到底是什么意思呢
就是a1 = b1-b2-b3+b4…
a2 = b2-b3+b4-b5…
依次类推
然后让我们求出满足a数组的b数组的元素。

解题思路:
乍一看感觉还挺难的,但其实只要出发点找对就so easy,我们发现an和bn是相同的,并且我们只要从bn倒推回来是不是就可以顺利找到答案了,在倒退过程中不难发现bn = an + an+1;
直接上代码

#include <iostream>
#include <cstdio>using namespace std;
const int maxn = 1e5+10;int A[maxn],B[maxn];//分别存储a,b数组int main () {int n;cin >> n;for(int i = 1;i <= n;i++) scanf("%d",&A[i]);B[n] = A[n];for(int i = n-1;i > 0;i--)//倒推找出数组b的每个元素B[i] = A[i]+A[i+1];for (int i = 1;i <= n;i++) {if(i == 1)cout << B[i];else cout << " " << B[i];}cout << "\n";return 0;
}

Memory and Crow(CodeForces 712A)相关推荐

  1. 【日常训练】Help Far Away Kingdom(Codeforces 99A)

    题意与分析 题意很简单,但是注意到小数可能有一千位,作为一周java选手的我选择了java解决. 这里的分析会归纳一些必要的Java API:(待补) 代码 /** ACM Code => cf ...

  2. RabbitMQ学习笔记:内存(Memory)|磁盘空间(Disk space)阀值

    相关文档指南: https://rabbitmq.com/memory.html 支持的单位符号 ## k, kiB: kibibytes (2^10 - 1,024 bytes) ## M, MiB ...

  3. 洛谷千题复习计划(一)(Codeforces + AtCoder)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 每天花一个小时简单复习一下我写过的洛谷的题目! 虽然还没有到千题,但是快了(等我复习完这些以后我 lu ...

  4. [题解]RGB Substring (hard version)-前缀和(codeforces 1196D2)

    题目链接:https://codeforces.com/problemset/problem/1196/D2 题意: q 个询问,每个查询将给你一个由 n 个字符组成的字符串s,每个字符都是 &quo ...

  5. Books Queries(codeforces 1066)

    You have got a shelf and want to put some books on it. You are given q queries of three types: L id ...

  6. World of Darkraft(codeforces 138D)

    题意:有一个 n × m 的棋盘,每个点上标记了 L; R; X 中的一个 每次能选择一个没有被攻击过的点 (i; j),从这个点开始发射线,射线形状为: 1. 若字符是 L,向左下角和右上角发,遇到 ...

  7. Sail(CodeForces - 298B )

    The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat ca ...

  8. Circling Round Treasures(codeforces 375c)

    题意:要求在一张网格图上走出一条闭合路径,不得将炸弹包围进去,使围出的总价值减去路径长度最大. /*类似于poj3182的做法,只不过出现了多个点,那么就用状态压缩的方法记录一个集合即可. */ #i ...

  9. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

最新文章

  1. 六月第一枪:股市震荡,下一步该做什么?
  2. 计算机未识别网络什么意思,win7 64位系统提示当前连接到未识别的网络怎么办...
  3. jQuery的end()方法使用详解
  4. NHibernate Step by Step (一) 转载
  5. js 循环拆词_js 各种循环语法
  6. PIL库自我学习总结及应用(美白,磨皮,搞笑图片处理)
  7. ubuntu vscode 配置字体_第五章 Ubuntu搭建ESP32开发环境(vscode)
  8. python爬虫之requests模块2
  9. 老漏洞easy击:CVE-2012 0158占顶!
  10. Python数据可视化之Pygal(雷达图)
  11. ASP.NET 备忘
  12. 51单片机外设篇:按键
  13. 在线PDF保护解除器,完全免费,没有文件数量限制 - PDF在线解锁器
  14. 金蝶系统服务器名称填什么,金蝶怎样输入服务器地址
  15. 树莓派系统安装和调试 总结整理篇
  16. Eclipse 工具上Springboot项目的简单 增删改查 的搭建
  17. 《软件方法》第二章 自测题
  18. 打印正三角形与倒三角形(C++)
  19. Java学习笔记 (码龄七年第一次写笔记 续2)
  20. Canvas制作简易涂鸦板

热门文章

  1. Word的常用操作和快捷键
  2. (从零开始)Cocos 3.6.0 接入微信小游戏激励广告
  3. php转换音频采样率,非整数倍SRC采样率转换问题样本试听
  4. VL102+IT6563替代方案|TYPEC转HDMI带PD方案|AG9311MAQ设计方案
  5. 如何有效阅读caffe源码
  6. Linux判断服务进程存在,存在则重启,不存在则启动
  7. 博尔赫斯-诗中的经典语段
  8. Jetson Nano控制SIM7020 开关机
  9. Xbox手柄转子马达的控制运用机制原理
  10. 计算机系统对工业相机影响,如何理解工业相机的校准