其他分享
首页 > 其他分享> > 1012 The Best Rank

1012 The Best Rank

作者:互联网

代码

#include <iostream>
#include <cstdio>
#include <string>
#include <set>
#include <vector>
using namespace std;
int r[1000000]={0};
char rc[1000000];
int crank[101]={-1};
int mrank[101]={-1};
int erank[101]={-1};
int arank[101]={-1};
struct pair_diy{
	string first;
	int second;
	int third;
	int forth;
	int fifth;
};
int main()
{
	pair_diy pa;
	int n,n2;
	string id;
	int c,m,e;
	int a;
	vector<pair_diy> vt;
	multiset<int> cs;
	multiset<int> ms;
	multiset<int> es;
	multiset<int> as;
	int f,l;
	int cnt=1;
	int tmp=0;
	int min; 
	char mini;
	cin>>n>>n2;
	for(int i=0;i<n;i++){
		cin>>id>>c>>m>>e;
		a=(c+m+e)/3;
		pa.first=id;
		pa.second=c;
		pa.third=m;
		pa.forth=e;
		pa.fifth=a;
		vt.push_back(pa);
		cs.insert(c);
		ms.insert(m);
		es.insert(e);
		as.insert(a);
	}
	for(multiset<int>::reverse_iterator rit=cs.rbegin();rit!=cs.rend();rit++){
		if(tmp==0){
			crank[*rit]=cnt;
			f=cnt;
			tmp=1;
			cnt++;
		}
		else if(tmp==1){
			if(crank[*rit]!=f){
				crank[*rit]=cnt;
				f=crank[*rit];
				cnt++;
			}
			else{
				crank[*rit]=f;
				cnt++;
			}
		}
	}
	tmp=0;
	cnt=1;
	for(multiset<int>::reverse_iterator rit=ms.rbegin();rit!=ms.rend();rit++){
		if(tmp==0){
			mrank[*rit]=cnt;
			f=cnt;
			tmp=1;
			cnt++;
		}
		else if(tmp==1){
			if(mrank[*rit]!=f){
				mrank[*rit]=cnt;
				f=mrank[*rit];
				cnt++;
			}
			else{
				mrank[*rit]=f;
				cnt++;
			}
		}
	}
	tmp=0;
	cnt=1;
	for(multiset<int>::reverse_iterator rit=es.rbegin();rit!=es.rend();rit++){
		if(tmp==0){
			erank[*rit]=cnt;
			f=cnt;
			tmp=1;
			cnt++;
		}
		else if(tmp==1){
			if(erank[*rit]!=f){
				erank[*rit]=cnt;
				f=erank[*rit];
				cnt++;
			}
			else{
				erank[*rit]=f;
				cnt++;
			}
		}
	}
	tmp=0;
	cnt=1;
	for(multiset<int>::reverse_iterator rit=as.rbegin();rit!=as.rend();rit++){
		if(tmp==0){
			arank[*rit]=cnt;
			f=cnt;
			tmp=1;
			cnt++;
		}
		else if(tmp==1){
			if(arank[*rit]!=f){
				arank[*rit]=cnt;
				f=arank[*rit];
				cnt++;
			}
			else{
				arank[*rit]=f;
				cnt++;
			}
		}
	}
	for(int i=0;i<vt.size();i++){
		min=2002;
		if(min>arank[vt[i].fifth]){
			min=arank[vt[i].fifth];
			mini='A';
		}
		if(min>crank[vt[i].second]){
			min=crank[vt[i].second];
			mini='C';
		}
		if(min>mrank[vt[i].third]){
			min=mrank[vt[i].third];
			mini='M';
		}
		if(min>erank[vt[i].forth]){
			min=erank[vt[i].forth];
			mini='E';
		}	
		r[stoi(vt[i].first)]=min;
		rc[stoi(vt[i].first)]=mini;
	}
	for(int i=0;i<n2;i++){
		cin>>id;
		if(i==0){
			if(r[stoi(id)]==0){
				cout<<"N/A";
			}
			else{
				cout<<r[stoi(id)]<<" "<<rc[stoi(id)];
			}	
		}
		else{
			if(r[stoi(id)]==0){
				cout<<endl<<"N/A";
			}
			else{
				cout<<endl<<r[stoi(id)]<<" "<<rc[stoi(id)];
			}
		}
	}
	return 0;
}

标签:tmp,cnt,int,rit,Rank,++,vt,1012,Best
来源: https://www.cnblogs.com/wodeblog1982/p/16494067.html