PAT A1012 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 (≤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 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 分)——多次排序,排名的更多相关文章
- PAT-1012 The Best Rank (25 分) 查询分数对应排名(包括并列)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- 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 ...
- A1012 The Best Rank (25)(25 分)
A1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...
- 1012 The Best Rank (25分) vector与结构体排序
1012 The Best Rank (25分) To evaluate the performance of our first year CS majored students, we con ...
- 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 ...
- PAT A1122 Hamiltonian Cycle (25 分)——图遍历
The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...
- PAT A1142 Maximal Clique (25 分)——图
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- [PAT] 1142 Maximal Clique(25 分)
1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
随机推荐
- 【nginx】详细配置说明
———————————————————————相关文章———————————————————————————— Centos之安装Nginx及注意事项 [Linux]nginx常用命令 ——————— ...
- HDU5543(SummerTrainingDay03-O DP)
Pick The Sticks Time Limit: 15000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- Android解析XML文件
XML文件和获取XML值 XML文件样例 <?xml version="1.0" encoding="utf-8"?> <citys> ...
- (网页)textarea去掉回车换行
转自CSDN: 1,把textarea内输入的内容中有回车换行的转成<br />传给后台, var content = $("#text").val().replace ...
- 成功清除 windows2008 内部版本7601 字眼
cmd—>bcdedit -set testsigning off重启电脑就好了
- 在ASP.NET Core中使用多环境
原文地址:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-2.1#star ...
- C#语言————第三章 使用属性升级MyBank
********常见的访问修饰符*********: public :公共的,可以在其他类中访问 private:私有的,只有在本类里可以使用,其他的类无权访问 类的默认访问修饰符 internal( ...
- 出现error: stray ‘\357’ in program的根源
分类: 编程语言/ C#/ 文章 这次又遇到这个这种问题,想找到它的根源.找到一个表格: The characters at a glance Here are all the printable c ...
- js计算两个日期的天数差值
js计算两个日期的天数差值 通过两个日期计算这两个日期之间的天数差值 /** * 计算天数差的函数,通用 * @param sDate1 * @param sDate2 * @returns {Num ...
- RTX服务端用户数据迁移说明
步骤一 最好在没有人使用RTX腾讯通的时候,这样你才能保证数据的实时同步;可以在服务器里面把RTX的相关服务器暂停再执行. 步骤二 进入RTX管理器用户数据----导出用户数据---还要把用户照片文件 ...