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 CME 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 (≤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 CM 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 <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = ;
struct stu{
int id;
int grade[];
};
vector<stu> vs;
int myrank[maxn][];
char list[] = { 'A', 'C', 'M', 'E' };
int now;
bool cmp(stu s1, stu s2){
return s1.grade[now] > s2.grade[now];
}
int main(){
int n, m;
scanf("%d %d", &n, &m);
for (int i = ; i<n; i++){
int id;
int c, m, e, a;
scanf("%d", &id);
scanf("%d %d %d\n", &c, &m, &e);
stu s;
s.id = id;
s.grade[] = c;
s.grade[] = m;
s.grade[] = e;
a = c + m + e;
s.grade[] = a;
vs.push_back(s);
}
for (now = ; now < ; now++){
sort(vs.begin(), vs.end(), cmp);
myrank[vs[].id][now] = ;
for (int k = ; k < n; k++){
if (vs[k].grade[now] != vs[k - ].grade[now]){
myrank[vs[k].id][now] = k + ;
}
else{
myrank[vs[k].id][now] = myrank[vs[k-].id][now];
}
}
}
for (int i = ; i < m; i++){
int j;
scanf("%d", &j); if (myrank[j][] != ){
int best = maxn, best_k = ;;
for (int k = ; k < ; k++){
if (myrank[j][k]<best){
best_k = k;
best = myrank[j][k];
}
}
printf("%d %c\n", myrank[j][best_k], list[best_k]);
}
else{
printf("N/A\n");
}
}
}

注意点:很简单的一道题目,却花了一个多小时,一开始题目意思理解错了,虽然就算理解对了,也一样。就觉得很麻烦,要开好多个数组,加好多属性,总觉得可能有捷径,就一直不下手。反思一下,就是要用最笨的最麻烦的方法先写出来,如果超时了,再去想哪里可以改进。这道题就是直接开个记录排名的数组,或者在结构体里加上各个成绩的排名属性,每个都排一下序,记录下来。这里唯一的小技巧是记录成绩用一个数组,而不是4个int,这样写cmp函数只要写一个。

PAT A1012 The Best Rank (25 分)——多次排序,排名的更多相关文章

  1. PAT-1012 The Best Rank (25 分) 查询分数对应排名(包括并列)

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  2. PAT A1146 Topological Order (25 分)——拓扑排序,入度

    This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...

  3. A1012 The Best Rank (25)(25 分)

    A1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...

  4. 1012 The Best Rank (25分) vector与结构体排序

    1012 The Best Rank (25分)   To evaluate the performance of our first year CS majored students, we con ...

  5. PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值

    题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: E ...

  6. PAT A1122 Hamiltonian Cycle (25 分)——图遍历

    The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...

  7. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  8. [PAT] 1142 Maximal Clique(25 分)

    1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...

  9. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  10. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

随机推荐

  1. Matlab 输入特殊字符

    下标用 _(下划线)  希腊字母等特殊字符用 \加拼音 如  α \alpha  β \beta  γ \gamma  θ \theta  Θ \Theta  Г \Gamma  δ \delta  ...

  2. MVC中返回json数据的两种方式

    MVC里面如果直接将数据返回到前端页面,我们常用的方式就是用return view(): 那么我不想直接用razor语法,毕竟razor这玩意儿实在是太难记了,还不如写ajax对接来得舒服不是 那么我 ...

  3. React中props

    今天让我们开启新的篇章好吧,来搞一搞React,以下所有操作都是我个人的一些理解,如果有错吴还请指出,想要看更全的可以去React官网可能一下子好吧 昨天按摩没到位,导致今天身体不太行,撸码千万别苦了 ...

  4. 卷积神经网络CNNs的理解与体会

    https://blog.csdn.net/shijing_0214/article/details/53143393 孔子说过,温故而知新,时隔俩月再重看CNNs,当时不太了解的地方,又有了新的理解 ...

  5. Ubuntu 16.04.4 LTS + Ambari 2.6.1.5 + HDP 2.6.4.0 安装部署

    服务器 主机名 master slave1 slave2 slave3 IP 192.168.1.40 192.168.1.41 192.168.1.42 192.168.1.43 离线包服务器: 1 ...

  6. Android学习笔记----ArcGIS在线地图服务(Android API)坐标纠偏

    仅限于如下ArcGIS在线地图服务(高德提供数据): //概述:彩色中文含兴趣点版中国基础地图 //投影:WGS 1984 Web-Mercator //切片格式:MIXED90 //服务类型:基础地 ...

  7. 【Java入门提高篇】Day33 Java容器类详解(十五)PriorityQueue详解

    今天要介绍的是基础容器类(为了与并发容器类区分开来而命名的名字)中的另一个成员——PriorityQueue,它的大名叫做优先级队列,想必即使没有用过也该有所耳闻吧,什么?没..没听过?emmm... ...

  8. Spring Boot 中配置文件application.properties使用

    一.配置文档配置项的调用(application.properties可放在resources,或者resources下的config文件夹里) package com.my.study.contro ...

  9. JMeter—前置处理器(九)

    参考<全栈性能测试修炼宝典JMeter实战>第六章 JMeter 元件详解中第四节前置处理器前置处理器用来处理请求前的一些准备工作,比如参数设置.环境变变量设置等 一.BeanShell ...

  10. 进程间通信——LINUX

    1.编写一段程序,使用系统调用fork( )创建两个子进程,再用系统调用signal( )让父进  程捕捉键盘上来的中断信号(即按ctrl+c键),当捕捉到中断信号后,父进程用系统调用kill( )向 ...