• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
村雨sup
自己选的路,跪着也要走完 XD
博客园    首页    新随笔    联系   管理    订阅  订阅
PAT 1012 The Best Rank
1012 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 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 (≤), 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 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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005
int n,m;
struct node{
    string s;
    int a,b,c,d;
};


struct cnm{
    int x;
    char q;
};

bool comp(const cnm a, const cnm b){
    if(a.x == b.x){
        if(a.q=='A') return 1;
        else if(a.q == 'C'&&b.q != 'A') return 1;
        else if(a.q == 'M'&&b.q != 'A'&&b.q != 'C') return 1;
        else return 0;
    }
    return a.x < b.x;

}


int main(){

    cin >> n >> m;
    node nod[n];
    for(int i=0;i < n;i++){
        cin >> nod[i].s >> nod[i].a >> nod[i].b >> nod[i].c;
        nod[i].d = (nod[i].a+nod[i].b+nod[i].c+0.5)/3;
    }

    map<int,int>mp;
    vector<int>temp;
    int cnt,beforenum;
    for(int i=0;i < n;i++){
        temp.push_back(nod[i].a);
    }
    sort(temp.begin(),temp.end());
    cnt = 1;
    beforenum = temp[temp.size()-1];
    for(int i=temp.size()-1;i>=0;i--){
        if(beforenum == temp[i])mp[temp[i]] = cnt;
        else{
            cnt = temp.size()-i;
            mp[temp[i]] = cnt;
        }
        beforenum = temp[i];
    }
    for(int i=0;i < n;i++){
        nod[i].a = mp[nod[i].a];
    }
    temp.clear();mp.clear();





    for(int i=0;i < n;i++){
        temp.push_back(nod[i].b);
    }
    sort(temp.begin(),temp.end());
    cnt = 1;
    beforenum = temp[temp.size()-1];
    for(int i=temp.size()-1;i>=0;i--){
        if(beforenum == temp[i])mp[temp[i]] = cnt;
        else{
            cnt = temp.size()-i;
            mp[temp[i]] = cnt;
        }
        beforenum = temp[i];
    }
    for(int i=0;i < n;i++){
        nod[i].b = mp[nod[i].b];
    }
    temp.clear();mp.clear();





    for(int i=0;i < n;i++){
        temp.push_back(nod[i].c);
    }
    sort(temp.begin(),temp.end());
    cnt = 1;
    beforenum = temp[temp.size()-1];
    for(int i=temp.size()-1;i>=0;i--){
        if(beforenum == temp[i])mp[temp[i]] = cnt;
        else{
            cnt = temp.size()-i;
            mp[temp[i]] = cnt;
        }
        beforenum = temp[i];
    }
    for(int i=0;i < n;i++){
        nod[i].c = mp[nod[i].c];
    }
    temp.clear();mp.clear();





    for(int i=0;i < n;i++){
        temp.push_back(nod[i].d);
    }
    sort(temp.begin(),temp.end());
    cnt = 1;
    beforenum = temp[temp.size()-1];
    for(int i=temp.size()-1;i>=0;i--){
        if(beforenum == temp[i])mp[temp[i]] = cnt;
        else{
            cnt = temp.size()-i;
            mp[temp[i]] = cnt;
        }
        beforenum = temp[i];
    }
    for(int i=0;i < n;i++){
        nod[i].d = mp[nod[i].d];
    }
    temp.clear();mp.clear();



    while(m--){
        string s1; cin >> s1;
        int pos = -1;
        for(int i=0;i < n;i++){
            if(nod[i].s == s1){pos = i;}
        }
        if(pos == -1){
            cout << "N/A" << endl;
        }
        else{
           cnm sb[4];
           sb[0].x = nod[pos].a;sb[0].q = 'C';
           sb[1].x = nod[pos].b;sb[1].q = 'M';
           sb[2].x = nod[pos].c;sb[2].q = 'E';
           sb[3].x = nod[pos].d;sb[3].q = 'A';
           sort(sb,sb+4,comp);
           cout << sb[0].x << " " << sb[0].q << endl;
        }

    }











    return 0;
}

//    for(auto num:temp)cout << num << " ";

//    map<int,int>::iterator it;
//    for(it=mp.begin();it!=mp.end();it++){
//        cout << it->first << " " << it->second << " ";
//    }

_写的超多。。这种题真的恶心。

复习了优先排序

排名并列应该1、1、3、4、5,而不是1、1、2、3、4,否则会有一个测试点不过

平均分是四舍五入的,所以需要按照+0.5后取整,保证是四舍五入的

 
posted on 2019-04-10 22:57  村雨sup  阅读(98)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3