1012 The Best Rank
Statement
Metadata
- 作者: CHEN, Yue
- 单位: 浙江大学
- 代码长度限制: 16 KB
- 时间限制: 200 ms
- 内存限制: 64 MB
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C
- C Programming Language, M
- Mathematics (Calculus or Linear Algrbra), and E
- English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C
, M
, E
and A
- Average of 4 students are given as the following:
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.
Input Specification
Each input file contains one test case. Each case starts with a line containing 2 numbers C
, M
and E
. Then there are
Output Specification
For each of the
The priorities of the ranking methods are ordered as A
C
M
E
. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output N/A
.
Sample Input
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
Sample Output
Solution
#include <bits/stdc++.h>
using namespace std;
#define maxn 2000
struct pp {
string ID;
int C, M, E, A, flag = 0;
int rank_C, rank_M, rank_E, rank_A, rank_min = INT_MAX;
char c;
} p[maxn];
int comp1(pp x, pp y) {
return x.C > y.C;
}
int comp2(pp x, pp y) {
return x.M > y.M;
}
int comp3(pp x, pp y) {
return x.E > y.E;
}
int comp4(pp x, pp y) {
return x.A > y.A;
}
int main() {
int N, M, i, j, flag;
cin >> N >> M;
map<string, pp> q;
string s;
for (i = 0; i < N; i++) {
cin >> s;
scanf("%d%d%d", &q[s].C, &q[s].M, &q[s].E);
q[s].A = (q[s].C + q[s].M + q[s].E) / 3;
q[s].flag = 1;
p[i].ID = s, p[i].C = q[s].C, p[i].M = q[s].M, p[i].E = q[s].E, p[i].A = q[s].A;
}
sort(p, p + i, comp1);
q[p[0].ID].rank_C = 1, flag = 1;
for (j = 1; j < i; j++) {
if (q[p[j].ID].C != q[p[j - 1].ID].C)
flag = j + 1;
q[p[j].ID].rank_C = flag;
}
sort(p, p + i, comp2);
q[p[0].ID].rank_M = 1, flag = 1;
for (j = 1; j < i; j++) {
if (q[p[j].ID].M != q[p[j - 1].ID].M)
flag = j + 1;
q[p[j].ID].rank_M = flag;
}
sort(p, p + i, comp3);
q[p[0].ID].rank_E = 1, flag = 1;
for (j = 1; j < i; j++) {
if (q[p[j].ID].E != q[p[j - 1].ID].E)
flag = j + 1;
q[p[j].ID].rank_E = flag;
}
sort(p, p + i, comp4);
q[p[0].ID].rank_A = 1, flag = 1, j = 0;
if (q[p[j].ID].rank_E < q[p[j].ID].rank_min) {
q[p[j].ID].rank_min = q[p[j].ID].rank_E;
q[p[j].ID].c = 'E';
}
if (q[p[j].ID].rank_M <= q[p[j].ID].rank_min) {
q[p[j].ID].rank_min = q[p[j].ID].rank_M;
q[p[j].ID].c = 'M';
}
if (q[p[j].ID].rank_C <= q[p[j].ID].rank_min) {
q[p[j].ID].rank_min = q[p[j].ID].rank_C;
q[p[j].ID].c = 'C';
}
if (q[p[j].ID].rank_A <= q[p[j].ID].rank_min) {
q[p[j].ID].rank_min = q[p[j].ID].rank_A;
q[p[j].ID].c = 'A';
}
for (j = 1; j < i; j++) {
if (q[p[j].ID].A != q[p[j - 1].ID].A)
flag = j + 1;
q[p[j].ID].rank_A = flag;
if (q[p[j].ID].rank_E < q[p[j].ID].rank_min) {
q[p[j].ID].rank_min = q[p[j].ID].rank_E;
q[p[j].ID].c = 'E';
}
if (q[p[j].ID].rank_M <= q[p[j].ID].rank_min) {
q[p[j].ID].rank_min = q[p[j].ID].rank_M;
q[p[j].ID].c = 'M';
}
if (q[p[j].ID].rank_C <= q[p[j].ID].rank_min) {
q[p[j].ID].rank_min = q[p[j].ID].rank_C;
q[p[j].ID].c = 'C';
}
if (q[p[j].ID].rank_A <= q[p[j].ID].rank_min) {
q[p[j].ID].rank_min = q[p[j].ID].rank_A;
q[p[j].ID].c = 'A';
}
}
for (i = 0; i < M; i++) {
cin >> s;
if (q[s].flag)
cout << q[s].rank_min << " " << q[s].c << endl;
else
cout << "N/A\n";
}
}