Solution
建一个桶 ,储存数组 ,考虑对于 ,考虑分讨 :
- 对于 ,显然无解。
- 对于 ,显然有解(即两袋各一个)。
- 对于 ,可以通过 次操作二使得 。
Code
#include <bits/stdc++.h>
#include <cstdio>
#define int long long
#define ull unsigned long long
#define mod 988444333
#define MOD 1000000007
#define in(x,y,z) x>=y&&x<=z
using namespace std;
const int N = 2e6 + 5;
inline int read ()
{
int x = 0;
char c = getchar ();
while (c < '0' || c > '9') c = getchar ();
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48),c = getchar ();
return x;
}
inline void write (int x)
{
if (x > 9) write (x / 10);
putchar (x % 10 + '0');
return ;
}
void solve ()
{
int n;
cin >> n;
map <int,int> bucket;
for (int i = 1;i <= n;i ++)
{
int x;
cin >> x;
bucket [x] ++;
}
for (int i = 1;i <= n;i ++)
{
if (bucket [i] == 1)
{
cout << "NO\n";
return ;
}
else if (bucket [i] > 2) bucket [i + 1] += bucket [i] - 2;
}
cout << "YES\n";
}
signed main ()
{
int T;
cin >> T;
while (T --) solve ();
return 0;
}