根据首篇题解
模拟了一个划方块的贪心
自觉思路没问题
但只有40pts
其他WA
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define maxn 1008600
int n, a[maxn] = {0};
struct p {
int v, num;
} b[maxn];
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + 1 + n);
int j = 0;
for (int i = 1; i <= n; i++) {
if (a[i] != a[i - 1]) {
j++;
b[j].v = a[i];
}
b[j].num++;
}//计数
/* for (int i = 1; i <= j; i++)
cout << b[i].v << " " << b[i].num << endl;
cout << endl;
cout << "j: " << j << endl;
*/ //测试输出
int ans = 1e8;
int tmp = 0;
for (int i = 1; i <= j; i++) {
if (b[i].num) {
tmp = 0;
for (int op = i; op <= j; op++) {
if ((b[op].num < b[op - 1].num || b[op].v != b[op - 1].v + 1 || !b[op].num) && op > i)
break;
else {
b[op].num--;
tmp++;
}
}
// cout << tmp << " ";测试
ans = min(ans, tmp);
}
}
cout << ans;
return 0;
}