pat1012(逆向計數排序的應用)

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

反向計數排序即可,注意優先級,a c m e .

代碼:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
using namespace std;
struct node{
    int c,m,e,a;
}st[10010];
int main(){
    int cc[110],mm[110],ee[110],aa[110];
    memset(cc,0,sizeof(cc));
    memset(mm,0,sizeof(mm));
    memset(aa,0,sizeof(aa));
    memset(ee,0,sizeof(ee));
    string num;
    int n,ms;
    int c,e,m,a;
    map<string,int>mp;
    scanf("%d%d",&n,&ms);
    for(int i = 1;i<=n;i++){
        cin>>num>>c>>m>>e;
        mp[num] = i;
        st[i].c = c;
        st[i].m = m;
        st[i].e = e;
        a = st[i].a = (c + m + e)/3;
        cc[c] += 1;
        mm[m] += 1;
        ee[e] += 1;
        aa[a] += 1;
    }
    for(int i = 100;i>=0;i--){
        cc[i] += cc[i+1];
        mm[i] += mm[i+1];
        ee[i] += ee[i+1];
        aa[i] += aa[i+1];//calculate the number of the <=
    }
    for(int i = 0;i<ms;i++){
        cin>>num;
        int x = mp[num];
        if(x == 0)puts("N/A");
        else {
            int c_ans = cc[st[x].c +1];
            int m_ans = mm[st[x].m +1];
            int e_ans = ee[st[x].e +1];
            int a_ans = aa[st[x].a +1];
            //find the minnum and put the char .
            int ans,ans1,ans2;
            char ar,ar1,ar2;
            if(a_ans <= c_ans){
                ans1 = a_ans;
                ar1 = 'A';
            }else {
                ans1 = c_ans;
                ar1 = 'C';
            }

             if(m_ans <= e_ans){
                ans2 = m_ans;
                ar2 = 'M';
            }else {
                ans2 = e_ans;
                ar2 = 'E';
            }

            if(ans1 <= ans2){
                ans = ans1;
                ar = ar1;
            }else{
                ans = ans2;
                ar = ar2;
            }
            printf("%d %c\n",ans+1,ar);

        }


    }

}



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