题解:AT_abc368_c [ABC368C] Triple Attack

· · 题解

思路

### 细节处理 这道题有点难度,因为 $T$ 是 $3$ 的倍数时能量会变成 $3$ 。这是个周期问题,自然会想到除法。**但是要注意到底什么时候它的能量会变成 $3$ !** 是 $T$ 为 $3$ 的倍数,不是这个敌人攻击了三的整数倍数次! ### 代码 ```cpp #include <cstdio> #include <iostream> #include <algorithm> using namespace std; int n, a[200010]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; long long cnt = 0; for (int i = 1; i <= n; i++) { int k = a[i] / 5; int x = cnt % 3; cnt += 1LL * k * 3; k = a[i] % 5; if (!k) continue; if (x == 0) { if (k <= 2) cnt += k; else cnt += 3; } else if (x == 1) { if (k <= 1) cnt++; else cnt += 2; } else if (x == 2) { if (k <= 3) cnt++; else cnt += 2; } } cout << cnt << endl; return 0; } ```