PAT 甲级 1012 The Best Rank
https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480
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; int n, m;
map<int, int> mp; struct Node{
int A, C, M, E;
int na, nc, nm, ne;
int id;
}node[2020]; bool cmpA(const Node& a, const Node& b) {
return a.A > b.A;
} bool cmpC(const Node& a, const Node& b) {
return a.C > b.C;
} bool cmpM(const Node& a, const Node& b) {
return a.M > b.M;
} bool cmpE(const Node& a, const Node& b) {
return a.E > b.E;
} void print(int idd) {
int a[8];
for(int i = 0; i < n; i ++)
if(node[i].id == idd) {
int temp = i;
a[0] = node[temp].na, a[1] = node[temp].nc, a[2] = node[temp].nm, a[3] = node[temp].ne;
sort(a, a + 4);
if(a[0] == node[temp].na)
printf("%d A\n", node[temp].na);
else if(a[0] == node[temp].nc)
printf("%d C\n", node[temp].nc);
else if(a[0] == node[temp].nm)
printf("%d M\n", node[temp].nm);
else
printf("%d E\n", node[temp].ne);
}
} int main() {
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i ++) {
scanf("%d%d%d%d", &node[i].id, &node[i].C, &node[i].M, &node[i].E);
node[i].A = (node[i].C + node[i].M + node[i].E) / 3;
mp[node[i].id] = 1;
}
sort(node, node + n, cmpA);
node[0].na = 1;
for(int i = 1; i < n; i ++) {
if(node[i].A == node[i - 1].A)
node[i].na = node[i - 1].na;
else node[i].na = i + 1;
}
sort(node, node + n, cmpC);
node[0].nc = 1;
for(int i = 1; i < n; i ++) {
if(node[i].C == node[i - 1].C)
node[i].nc = node[i - 1].nc;
else node[i].nc = i + 1;
}
sort(node, node + n, cmpM);
node[0].nm = 1;
for(int i = 1; i < n; i ++) {
if(node[i].M == node[i - 1].M)
node[i].nm = node[i - 1].nm;
else node[i].nm = i + 1;
}
sort(node, node + n, cmpE);
node[0].ne = 1;
for(int i = 1; i < n; i ++) {
if(node[i].E == node[i - 1].E)
node[i].ne = node[i - 1].ne;
else node[i].ne = i + 1;
}
while(m --) {
int x;
scanf("%d", &x);
if(!mp[x])
printf("N/A\n");
else
print(x);
}
return 0;
}
几乎看了一个下午的搜索 头皮发麻 这个代码觉得写得好麻烦 恰饭去了
PAT 甲级 1012 The Best Rank的更多相关文章
- PAT甲级1012. The Best Rank
PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- PAT甲级——1012 The Best Rank
PATA1012 The Best Rank To evaluate the performance of our first year CS majored students, we conside ...
- PAT——甲级1012:The Best Rank(有坑)
1012 The Best Rank (25 point(s)) To evaluate the performance of our first year CS majored students, ...
- PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏
1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- pat甲级1012
1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...
- 【PAT】1012. The Best Rank (25)
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...
- PAT甲级——A1012 The Best Rank
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT甲级1012题解——选择一种合适数据存储方式能使题目变得更简单
题目分析: 本题的算法并不复杂,主要是要搞清楚数据的存储方式(选择一种合适的方式存储每个学生的四个成绩很重要)这里由于N的范围为10^6,故选择结构体来存放对应下标为学生的id(N只有2000的范围, ...
随机推荐
- day 22 内置的模块
1.简单的理解模块 写的每一个py文件都是一个模块,还有一些是我们一直在使用的模块. buildins: 内置模块. print, input random 主要是和随机相关的内容: ...
- GitLab 基本操作
登录 在浏览其中输入http://192.168.3.11:8888 如图1登录界面. 图1 注:第一次新增用户,会发送修改密码链接到用户的邮箱中,用户会收到如图2邮件. 图2 2. 修改密码 点 ...
- B/S与C/S架构简介
概念: C/S结构,即Client/Server(客户机/服务器)结构,是大家熟知的软件系统体系结构,通过将任务合理分配到Client端和Server端,降低了系统的通讯开销,可以充分利用两端硬件环境 ...
- BugkuWeb本地包含
知识点:$_REQUEST不是一个函数,它是一个超全局变量,里面包括有$_GET $_POST $_COOKIE的值,$_REPUEST 是接收了 $_GET $_POST $_COOKIE 三个的集 ...
- STM32 USB设备描述符、配置描述符、端点描述符含义
查了一整天的资料,自己把不懂的全部试了一遍 一下是程序以及注释 /* USB设备描述符*/ const uint8_t CustomHID_DeviceDescriptor[CUSTOMHID_SIZ ...
- 贪心算法之Dijkstra
贪心算法的主要思想就是通过不断求解局部最优解,最后求出最优解或者最优解的近似值,不能保证一定为最优解. Dijistra算法,选取没有选择过的点到已经选择过得点组成的集合中最短的距离的点.然后更新已选 ...
- E. Almost Regular Bracket Sequence
题目链接:http://codeforces.com/contest/1095/problem/E 解题心得: 刚开始拿到这个题的时候还真的没什么思路,后来仔细想想还是比较简单的.首先题目要求翻转一个 ...
- EL/JSTL-jsp页面更简单的输出方式
1.EL(Expression Language):表达式语言,用于页面输出 格式:${表达式} EL支持四则运算,关系运算[常用eq来比较字符串或判断相等],逻辑运算 EL访问空间内对象,[类.对象 ...
- 滑雪_KEY
滑雪 ( skiing.pas/c/cpp) [题目描述] MM 参加一个滑雪比赛,滑雪场是一个 N×M 的矩形, MM 要从起点( 1, 1)滑到( N,M).矩形中每个单位格子有一个海拔高度值 h ...
- 佛山Uber优步司机奖励政策(1月11日~1月17日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...