A1012(23msAC)

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<string>
#include<cctype>
using namespace std;
/*
题意:给出学生人数和查询的id  给出该学生最好的排名并给出相应的科目
分析:记录相应id及其对应的分数,给id的序号排序这样可以最大程度的减少时间开销,因为结点的移动时间开销要大的多
注意:1.未查到的给出N/A 2。ACME优先级
*/
const int maxn = 1000010;
int n, M, id[maxn], score[4][maxn], r[4][maxn],j;
bool cmp(int x, int y) {
	return score[j][x] > score[j][y];
}
int main() {
	unordered_map<int, bool> exist;
	cin >> n >> M;
	for (int i = 0; i < n; ++i) {
		int ID;
		scanf("%d", &ID);
		id[i] = ID;
		scanf("%d %d %d", &score[1][ID], &score[2][ID], &score[3][ID]);
		score[0][ID] = score[1][ID] + score[2][ID] + score[3][ID];
		exist[ID] = 1;
	}
	for (j = 0; j < 4; ++j) {
		sort(id, id + n, cmp);
		int indx = id[0];
		r[j][indx] = 1;
		for (int i = 1; i < n; ++i) {
			r[j][id[i]] = i + 1;
			if (score[j][id[i]] == score[j][id[i - 1]]) r[j][id[i]] = r[j][id[i - 1]];
		}
	}
	char mp[4] = { 'A','C','M','E' };
	while (M--) {
		int ID, rankk = maxn, course;;
		scanf("%d", &ID);
		if (exist[ID] == 0) printf("N/A\n");
		else {
			
			for (int i = 0; i < 4; ++i) {
				if (r[i][ID] < rankk) {
					rankk = r[i][ID];
					course = i;
				}
			}
			printf("%d %c\n", rankk, mp[course]);
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值