1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Codeforces 712A. Memory and Crow

Codeforces 712A. Memory and Crow

时间:2022-08-05 15:14:57

相关推荐

Codeforces 712A. Memory and Crow

题目链接:/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);11ios_base::sync_with_stdio(); cin.tie();12int n; cin >> n;13for(int i = 1; i <= n; i++) cin >> a[i];14for(int i = 1; i <= n; i++) cout << a[i] + a[i + 1] << (i == n ? "\n" : " ");15return 0;16 }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。