2019-05-18 08:48:27 加油,加油,堅持!!! 這道題我沒有想出公式推導,只是按照模擬題來做,第5個樣例超時 樣例超時,方法錯誤 https://www.cnblogs.com/ECJTUACM-873284962/p/6375011.html AC代碼: 我的代碼: ...
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; }