Codeforces 1265C Beautiful Regional Contest

思路:

1.贪心思想,我们就只让解最多题的那一类拿金牌;
2.然后依次往后排银牌,直到银牌数比金牌多;然后再继续排铜牌,因为要保证获奖的尽可能多嘛,那就排到一半人为止就ok了;
3.凡是上述步骤中出现异常情况,统统都输出0 0 0即可,比如发现一半人数都用完了,银牌或者铜牌的数量都没办法超过金牌数;

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
const int maxn=1e6+99;
int cnt[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int t; cin>>t;
	while(t--){
		map<int,int,greater<int>> cnt;
		int n; cin>>n;
		vector<int> v; int sz=-1;
		for(int i=0;i<n;i++){
			int p; cin>>p; cnt[p]++;
			if(sz==-1||v[sz]!=p) v.pb(p),sz++;
		}
		int g=cnt[v[0]],s=cnt[v[1]],b=0; int pos=2;
		while(true){
			if(pos==v.size()||s+g>(n>>1)){
				cout<<"0 0 0
"; goto out;
			}
			if(s>g) break;
			s+=cnt[v[pos++]];
		}
		while(true){
			if(pos==v.size()||s+g+b+cnt[v[pos]]>(n>>1)) break;
			b+=cnt[v[pos++]];
		}
		if(b<=g)cout<<"0 0 0
";
		else cout<<g<<' '<<s<<' '<<b<<'
';
		out:;
		for(int x:v) cnt[x]=0;
	}
	return 0;
}
原文地址:https://www.cnblogs.com/yuhan-blog/p/12308761.html