Codeforces 712A. Memory and Crow

题目链接:http://codeforces.com/problemset/problem/712/A

题意:

  有两个序列 ai 和 bi, 长度都为 n, 对于序列 ai 满足 ai = bi - bi + 1 + bi + 2 - bi + 3 ...(i < n).现给你 ai, 让你求出 bi.

思路:

  ai = bi - bi + 1 + bi + 2 - bi + 3 ...(i < n).

  ai + 1 = bi + 1 - bi + 2 + bi + 3 ...  (i < n).

  对于上式相加就可以得到 ai + ai + 1 = bi.

代码:

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 typedef long long LL;
 5 
 6 const int MAXN = 100000;
 7 int a[MAXN + 3];
 8 
 9 int main() {
10     //freopen("input", "r", stdin);
11     ios_base::sync_with_stdio(); cin.tie();
12     int n; cin >> n;
13     for(int i = 1; i <= n; i++) cin >> a[i];
14     for(int i = 1; i <= n; i++) cout << a[i] + a[i + 1] << (i == n ? "
" : " ");
15     return 0;
16 }
原文地址:https://www.cnblogs.com/Ash-ly/p/5861327.html