The Best Rank (25)
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 Algebra), 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
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 M lines, each containing a student ID.
Output
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
题目大意:给出学号 C 数学 英语 成绩 计算出评价成绩 分别求这些成绩的排名 然后输出一个学生排序最靠前的科目或评价分 排名相同时 优先级 平均分>C>数学>英语
分析:直接计算就好 另外注意成绩的排名 分数都是int型 包括平均分要四舍五入 然后分数相同排名也相同 但是下一个人的排名不受影响 例如样例中平均分的排名为 1 2 3 3 5 开始没理解到点 分数给的double型 几个测试点错了
/*
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
310105 85 90 90 88
例如这里 最后一列平均分的排名为 2 5 3 1 3
*/
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 2020
using namespace std;
int now;
struct node{
char id[8];
int gd[4];//记录成绩
int st[4];//记录名次
};
node peo[maxn];
int cmp(node a,node b){
return a.gd[now]>b.gd[now];
}
int cmp_i(node a,node b){
return strcmp(a.id,b.id)<0;
}
int main()
{
int n,m;
char id[8];
scanf("%d%d",&n,&m);
for(int i=0;i<n;++i){
scanf("%s%d%d%d",peo[i].id,&peo[i].gd[1],&peo[i].gd[2],&peo[i].gd[3]);
peo[i].gd[0]=round((peo[i].gd[1]+peo[i].gd[2]+peo[i].gd[3])/3.0);
}
for(now=0;now<4;++now){//分别对4个成绩排序 记录名次
sort(peo,peo+n,cmp);
peo[0].st[now]=1;
for(int i=1;i<n;++i){//相同分数名次相同
if(peo[i].gd[now]==peo[i-1].gd[now])
peo[i].st[now]=peo[i-1].st[now];
else
peo[i].st[now]=i+1;
}
}
sort(peo,peo+n,cmp_i);
for(int i=0;i<m;++i){
scanf("%s",id);
int l=0,r=n,m,flag=0;
while(l<=r){//二分搜索找到该学生
m=(l+r)/2;
int tem=strcmp(id,peo[m].id);
if(tem==0){
flag=1;
break;
}
else if(tem<0)
r=m-1;
else
l=m+1;
}
if(flag==0){
printf("N/A\n");
continue;
}
int max_s=n+1,mark=-1;
for(int j=0;j<4;++j){//找到后记录最高名次和输出科目
if(peo[m].st[j]<max_s){
max_s=peo[m].st[j];
mark=j;
}
}
printf("%d ",max_s);
if(mark==0)
printf("A\n");
else if(mark==1)
printf("C\n");
else if(mark==2)
printf("M\n");
else if(mark==3)
printf("E\n");
}
return 0;
}