codeforces 712A. Memory and Crow
Posted artimis-fightting
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 712A. Memory and Crow相关的知识,希望对你有一定的参考价值。
2019-05-18
08:48:27
加油,加油,坚持!!!
这道题我没有想出公式推导,只是按照模拟题来做,第5个样例超时
样例超时,方法错误
https://www.cnblogs.com/ECJTUACM-873284962/p/6375011.html
AC代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll max_n = 1e5 + 5; ll a[max_n]; ll b[max_n]; int main() { ll n; ll i, j; scanf("%lld", &n); for(i = 0; i < n; i++) { scanf("%lld", &a[i]); } for(i = 0; i < n - 1; i++) { b[i] = a[i] + a[i + 1]; cout << b[i] << " "; } b[n - 1] = a[n - 1]; cout << b[n - 1] ; return 0; }
我的代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll max_n = 1e5 + 5; ll a[max_n]; ll b[max_n]; int main() { ll n; ll i, j; scanf("%lld", &n); for (i = 1; i <= n; i++) { scanf("%lld", &a[i]); } b[n] = a[n]; //超时 for (i = n - 1; i >= 1; i--) { ll count = 0; ll m = 1; for (j = i + 1; j <= n; j++) { count = count + (m * b[j]); m = m * -1; } b[i] = a[i] + count; } for (i = 1; i <= n; i++) { if (i == n) { cout << b[i]; } else { cout << b[i] << " "; } } return 0; }
以上是关于codeforces 712A. Memory and Crow的主要内容,如果未能解决你的问题,请参考以下文章