#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;
}
A1012(23msAC)
这是一个关于学生分数管理的程序,实现了根据学生ID查询其在各科目(ACME)中的排名,并给出最佳科目。程序使用了C++编写,通过优先级排序,快速查找每个学生在所有科目中的最优排名。当查询的学生ID不存在时,返回'N/A'。
摘要由CSDN通过智能技术生成