zoukankan      html  css  js  c++  java
  • 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
      1 #include<stdio.h>
      2 #include<math.h>
      3 #include<stdlib.h>
      4 #include<string.h>
      5 #include<algorithm>
      6 using namespace std;
      7 
      8 struct Stu
      9 {
     10     int id;
     11     int c, m, e, a;
     12 };
     13 bool cmp1(Stu x, Stu y)
     14 {
     15     return x.a > y.a;
     16 }
     17 bool cmp2(Stu x, Stu y)
     18 {
     19     return x.c > y.c;
     20 }
     21 bool cmp3(Stu x, Stu y)
     22 {
     23     return x.m > y.m;
     24 }
     25 bool cmp4(Stu x, Stu y)
     26 {
     27     return x.e > y.e;
     28 }
     29 Stu s[2010];
     30 int r[1000000][5] = {};
     31 int main()
     32 {
     33     int n, m, i;
     34     char course[10] = {'A', 'C', 'M', 'E'};
     35     scanf("%d%d", &n, &m);
     36     for(i = 0; i < n; i++)
     37     {
     38         scanf("%d%d%d%d", &s[i].id, &s[i].c, &s[i].m, &s[i].e);
     39         s[i].a = (s[i].c + s[i].m + s[i].e) / 3;
     40     }
     41     sort(s, s + n, cmp1);
     42     r[s[0].id][0] = 1;
     43     for(i = 1; i < n; i++)
     44     {
     45         if(s[i].a == s[i - 1].a)
     46         {
     47             r[s[i].id][0] = r[s[i - 1].id][0];
     48         }
     49         else
     50         {
     51             r[s[i].id][0] = i + 1;
     52         }
     53     }
     54     sort(s, s + n, cmp2);
     55     r[s[0].id][1] = 1;
     56     for(i = 1; i < n; i++)
     57     {
     58         if(s[i].c == s[i - 1].c)
     59         {
     60             r[s[i].id][1] = r[s[i - 1].id][1];
     61         }
     62         else
     63         {
     64             r[s[i].id][1] = i + 1;
     65         }
     66     }
     67     sort(s, s + n, cmp3);
     68     r[s[0].id][2] = 1;
     69     for(i = 1; i < n; i++)
     70     {
     71         if(s[i].m == s[i - 1].m)
     72         {
     73             r[s[i].id][2] = r[s[i - 1].id][2];
     74         }
     75         else
     76         {
     77             r[s[i].id][2] = i + 1;
     78         }
     79     }
     80     sort(s, s + n, cmp4);
     81     r[s[0].id][3] = 1;
     82     for(i = 1; i < n; i++)
     83     {
     84         if(s[i].e == s[i - 1].e)
     85         {
     86             r[s[i].id][3] = r[s[i - 1].id][3];
     87         }
     88         else
     89         {
     90             r[s[i].id][3] = i + 1;
     91         }
     92     }
     93     for(i = 0; i < m; i++)
     94     {
     95         int temp;
     96         scanf("%d", &temp);
     97         if(r[temp][0] == 0)
     98         {
     99             printf("N/A
    ");
    100         }
    101         else
    102         {
    103             int k = 0;
    104             for(int j = 0; j < 4; j++)
    105             {
    106                 if(r[temp][j] < r[temp][k])
    107                 {
    108                     k = j;
    109                 }
    110             }
    111             printf("%d %c
    ", r[temp][k], course[k]);
    112         }
    113     }
    114     return 0;
    115 }
  • 相关阅读:
    JLable设置复制粘贴
    JLable设置背景颜色
    JFrame 居中显示
    String、StringBuffer、StringBuiler区别
    java读取本地文件
    mybatis 添加后获得该新增数据自动生成的 id
    验证身份证号规则(验证身份证号是否正确)
    MyBatis like (模糊查询)
    MyBatis if test 传入一个数字进行比较报错 There is no getter for property named 'userState' in 'class java.lang.Integer'
    Redis 中 byte格式 写入、取出
  • 原文地址:https://www.cnblogs.com/yomman/p/4278225.html
Copyright © 2011-2022 走看看