1012 The Best Rank (25分)
注意点:
排名为111456不是111234
代码:
#include<iostream>//AC
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 1e7;
struct node {
int id;
int score[4];
};
char s[5] = { 'A','C','M','E' };
int Rank[5][maxn] = { {0} }, flag = -1;
bool cmp1(node p, node q) {//参考柳神
return p.score[flag]>q.score[flag];
}
int main() {
int n, l, id, c, m, e, a;
vector<node> stu;
scanf("%d%d", &n, &l);
for (int i = 0; i < n; i++) {
node t;
scanf("%d%d%d%d", &id, &c, &m, &e);
a = round(((double)(c + m + e) / 3));//不四舍五入也能过。。。
t = { id,a,c,m,e };
stu.push_back(t);
}
for (flag = 0; flag < 4; flag++) {
sort(stu.begin(), stu.end(), cmp1);
int t = stu[0].score[flag], cnt = 1;
Rank[flag][stu[0].id] = cnt;
for (int i = 1; i < stu.size(); i++) {
if (stu[i].score[flag] == t) {
Rank[flag][stu[i].id] = cnt;
}
else {
t = stu[i].score[flag];
cnt = i + 1;
Rank[flag][stu[i].id] = cnt;
}
}
}
for (int i = 0; i < l; i++) {
int Min = 1e9;
cin >> id;
for (int j = 0; j < 4; j++) {
if (Rank[j][id] == 0) { break; }
if (Rank[j][id] < Min) {
Min = Rank[j][id];
c = j;
}
}
if (Min == 1e9) {
printf("N/A\n");
}
else {
printf("%d %c\n", Min, s[c]);
}
}
return 0;
}