1012. The Best Rank

1012. The Best Rank (25)

時間限制
400 ms
內存限制
65536 kB
代碼長度限制
16000 B
判題程序
Standard
作者
CHEN, Yue

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

提交代

唉,注意一點,相同分數算作排名相同,所以91,90,88,88,84的排名應該是1,2,3,3,5。不能算作1,2,3,3,4。別的沒什麼。

#include<bits/stdc++.h>
using namespace std;
struct grade{
    int pos;
    int ranks;
};
struct score{
    bool flag;
    grade g[4];
}st[1000005];
struct Student{
    int no;
    int c;
    int m;
    int e;
    int a;
}s[2005];
bool cmp1(Student a, Student b){
    if(a.c!=b.c) return a.c>b.c;
    return a.no<b.no;
}
bool cmp2(Student a, Student b){
    if(a.m!=b.m) return a.m>b.m;
    return a.no<b.no;
}
bool cmp3(Student a, Student b){
    if(a.e!=b.e) return a.e>b.e;
    return a.no<b.no;
}
bool cmp4(Student a, Student b){
    if(a.a!=b.a) return a.a>b.a;
    return a.no<b.no;
}
bool cmp5(grade a, grade b){
    if(a.ranks != b.ranks) return a.ranks<b.ranks;
    return a.pos<b.pos;
}
int main(){
    int n,m;
    char pp[4]={'A','C','M','E'};
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++){
        scanf("%d%d%d%d",&s[i].no,&s[i].c,&s[i].m,&s[i].e);
        s[i].a=(s[i].c+s[i].m+s[i].e)/3;
        st[s[i].no].flag=1;
    }
    sort(s+1,s+1+n,cmp1);
    int len=0;
    for(int i=1;i<=n;i++){
        if(s[i].c==s[i-1].c)
            st[s[i].no].g[0].ranks=st[s[i-1].no].g[0].ranks;
        else
            st[s[i].no].g[0].ranks=i;
        st[s[i].no].g[0].pos=1;
    }
    sort(s+1,s+1+n,cmp2);
    len=0;
    for(int i=1;i<=n;i++){
        if(s[i].m==s[i-1].m)
            st[s[i].no].g[1].ranks=st[s[i-1].no].g[1].ranks;
        else
            st[s[i].no].g[1].ranks=i;
        st[s[i].no].g[1].pos=2;
    }
    sort(s+1,s+1+n,cmp3);
    len=0;
    for(int i=1;i<=n;i++){
        if(s[i].e==s[i-1].e)
            st[s[i].no].g[2].ranks=st[s[i-1].no].g[2].ranks;
        else
            st[s[i].no].g[2].ranks=i;
        st[s[i].no].g[2].pos=3;
    }
    sort(s+1,s+1+n,cmp4);
    len=0;
    for(int i=1;i<=n;i++){
        if(s[i].a==s[i-1].a)
            st[s[i].no].g[3].ranks=st[s[i-1].no].g[3].ranks;
        else
            st[s[i].no].g[3].ranks=i;
        st[s[i].no].g[3].pos=0;
    }
    int no;
    while(m--){
        scanf("%d", &no);
        if(st[no].flag!=1){printf("N/A\n");}
        else{
            sort(st[no].g,st[no].g+4, cmp5);
            printf("%d %c\n", st[no].g[0].ranks, pp[st[no].g[0].pos]);
        }
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章