下面是被打回的源码,原因是 LaTeX 公式/英文与汉字之间少空格,求各位大佬们查一下错(悬2关)
# 题目大意
有一个环,环上有 $14$ 个孔,每个孔里有 $a_i$ 个石头,选择一个孔,将剩下的石头顺次放到后面的孔中。
偶数个石头的洞里的石头数就是得分,求一次移动后得到的最高分数是多少。
# 思路
$n = 14$,考虑枚举每一个孔洞,如果纯暴力模拟分发过程的话,$a_i \leq 10^9$,肯定超时。我们可以考虑用除法优化,具体来说就是:每个孔都可以分到 $\frac{n}{14}$ 个,余数再来暴力模拟,余数不会超过 $13$,时间复杂度可以接受。
# 代码
```cpp
#include <bits/stdc++.h>//万能头大法
using namespace std;
#define int long long//不开long long见祖宗
int a[20], b[20];
signed main() {
int n = 14, ans = -10;//这里定义n=14是为了方便后面处理。
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i];
}
for (int i = 1; i <= n; i++) {//枚举每个洞
for (int j = 1; j <= n; j++)//多测不清空,0分两行泪
a[j] = b[j];
if (!a[i])//0不用考虑
continue;//这里的判断要写在复原之后!!!
int x = a[i] / n, y = a[i] % n;
for (int j = 1; j <= n; j++)
a[j] += x;//每个洞分到n/14个石头
a[i] = x;//本身要特殊处理
for (int j = i + 1; y; j++) {
if(j==15)//这里不能用模!i=14就寄了!!
j = 1;
a[j]++;
y--;
}
int sum = 0;
for (int j = 1; j <= n; j++)
if (a[j] % 2 == 0)//统计
sum += a[j];
ans = max(sum, ans);//更新
}
cout << ans;
return 0;
}