Contents
  1. 1. Input Specification:
  2. 2. Output Specification:
  3. 3. Sample Input:
  4. 4. Sample Output:

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:

StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91

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 N and M (≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are Mlines, each containing a student ID.

Output Specification:

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

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:

1 C
1 M
1 E
1 A
3 A
N/A

题目大意:每个学生都有A(平均成绩)、C(c语言成绩)、M(数学成绩)、E(英语成绩)以及各项成绩的排名。给出一个学生编号,要求给出该学生四项排名中的最好排名以及该项简写代码。

分析:用一个存储体记录学生的编号(id),按ACME的顺序存储各科成绩(score[0]~score[4])和各科排名(rank[0] ~ rank[4])。用sort函数和flag对四科进行排序,将排名结果放到该学生rank中的相应位置。用exist[1000010]存储学生在结构体中的编号。(为了防止node[0]和不存在的情况混淆,将编号做+1处理,要具体操作的时候再-1)对每一个查询query,返回其在node数组中的下标p。如果p==-1,说明该学生不存在;p!=-1,查找node[p]中rank的最小值,并输出其对应的科目。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int flag,exist[1000010];
struct Node{
int id;
int score[4];
int rank[4];
}node[2010];
bool cmp(Node a,Node b){ return a.score[flag] > b.score[flag]; }
int main(){
int N,M,id,query,p;
scanf("%d %d",&N,&M);
for (int i=0;i<N;i++){
scanf("%d %d %d %d", &node[i].id, &node[i].score[1], &node[i].score[2], &node[i].score[3]);
//三项和再加1是为了四舍五入
node[i].score[0] = (node[i].score[1] + node[i].score[2] + node[i].score[3] + 1) / 3 ;
}
//给每一项进行排序,并排名写入该学生的rank数组
for (flag=0;flag<4;flag++){
sort(node,node+N,cmp);
node[0].rank[flag] = 1;
for (int j=1;j<N;j++){
if (node[j].score[flag] == node[j-1].score[flag])
node[j].rank[flag] = node[j-1].rank[flag];
else node[j].rank[flag] = j+1;
}
}
//让学生编号和存储体中位置对应
for (int i=0;i<N;i++) exist[node[i].id] = i+1;
char dict[5] = {'A','C','M','E'};
//进行查询
for (int i=0;i<M;i++){
scanf("%d",&query);
p = exist[query]-1;
if (p != -1){
int min=node[p].rank[0],pos=0;
for (int j=1;j<4;j++){
if (node[p].rank[j] < min){
min = node[p].rank[j];
pos = j;
}
}
printf("%d %c\n",min,dict[pos]);
}
else printf("N/A\n");
}
return 0;
}
Contents
  1. 1. Input Specification:
  2. 2. Output Specification:
  3. 3. Sample Input:
  4. 4. Sample Output: