https://codeforces.com/contest/1506/problem/D
思路:
首先转化成把颜色都统计下来扔到map里。问题就变成了每次选两个数然后-1,问能否全部消完。那么就是个原题了
https://codeforces.com/problemset/problem/1201/B
每次消去相同的两个数,则其和为偶数才能消去。同时注意最大值要小于等于剩下,才能消完。剩下的数先合并成一个>=最大值的数,然后再消
https://codeforces.com/problemset/problem/1201/B代码:
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
LL a[maxn];
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL n;cin>>n;
for(LL i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n);
LL sum=0;
for(LL i=1;i<=n;i++){
sum+=a[i];
}
if(sum%2==0&&a[n]<=sum-a[n]){
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
return 0;
}
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn];
map<LL,LL>map1;
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL t;cin>>t;
while(t--){
LL n;cin>>n;
LL sum=0;LL cnt=0;
map1.clear();
for(LL i=1;i<=n;i++){
cin>>a[i];
LL res=++map1[a[i]];
if(res>cnt) cnt=res;
}
cnt=n-cnt;
if(cnt*2>=n&&(n&1)) cout<<1<<"\n";
else if(n<=cnt*2) cout<<"0"<<"\n";
else cout<<n-cnt*2<<"\n";
}
return 0;
}