贪心, 优先找对子, 有一种特殊情况1 2 3 3 4 5这种情况优先顺子
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXN = 1e6 + 5;
int arr[MAXN];
int main() {
int n, res;
while (cin >> n) {
res = 0;
memset(arr, 0, sizeof(arr));
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
arr[t]++;
}
for (int i = 1; i <= MAXN - 1; ++i) {
if (arr[i - 1] == 1 && arr[i - 2] == 1 && arr[i] > 0) {
arr[i]--;
arr[i - 1]--;
arr[i - 2]--;
res++;
}
res += arr[i] / 2;
arr[i] %= 2;
}
cout << res << endl;
}
}