https://vjudge.net/contest/238207#problem/G
采用贪心策略
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
const int N = 100000;
int n, a[N + 5], d;
int main()
{
while (scanf("%d", &n)==1)
{
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++) {
scanf("%d", &d);
a[d]++;
}
int ans = 0;
for (int i = 1; i <= N; i++)
{
if (a[i - 1] == 1 && a[i - 2] == 1 && a[i] > 0) {
a[i]--;
a[i - 1]--;
a[i - 2]--;
ans++;
}
ans += a[i] / 2;
a[i] %= 2;
}
printf("%d\n", ans);
}
}