标签:const 公式 mem names scan lock ++ 坚持 logs
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
标签:const 公式 mem names scan lock ++ 坚持 logs
原文地址:https://www.cnblogs.com/Artimis-fightting/p/10884595.html