给你一个长度为 \(n\) 的整数数组 \(a\), 你可以进行 0 次或多次下列操作:
例如:\(n=6\) , \(a = [1,6,1,1,4,4]\) ,然后你执行以下操作:
怎样操作能让数组的大小最小? 输出最小长度可能为多少
利用 \(map\) 映射来获取最多的数字的数量,将该数字数量记作 \(mx\)
根据贪心,我们可以得出以下结论
思维 CF 1400 贪心
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int T;
	cin >> T;
	while(T--){
		ll n;
		cin >> n;
		
		map<ll,ll> mp;
		ll mx = 0,x;
		for(int i = 0 ; i < n ; i++){
			cin >> x;
			mx = max(mx,++mp[x]);
		}
		
		cout << max(n%2,2*mx-n) << endl;
	}
}
Codeforces 1506D Epic Transformation
原文:https://www.cnblogs.com/ieeeev/p/14591933.html