思路
很大,导致 可能也会很大,所以一遍一遍的模拟就会超时。我们发现,题中有一个要求:每次必须打离自己最近的活着的敌人。我们就只用枚举每个敌人即可,在枚举的过程中计算答案。
细节处理
这道题有点难度,因为 是 的倍数时能量会变成 。这是个周期问题,自然会想到除法。但是要注意到底什么时候它的能量会变成 ! 是 为 的倍数,不是这个敌人攻击了三的整数倍数次!
代码
#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;
}