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 (≤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
分析:sort排序题,由于要记录每科成绩的排名,可以用Rank[id][now]来记录学科排名,如果直接记录在结构体里面会超时,因为每次查询时需要遍历一遍,查询数量足够大的时候会超时。
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-25-15.41.18
* Description : A1012
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
struct Student{
int id;
];//4门成绩
}stu[];
]={'A','C','M','E'};
int now;
bool cmp(Student a,Student b){
return a.grade[now]>b.grade[now];
}
][]={};
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int n,m;
scanf("%d%d",&n,&m);
;i<n;i++){
scanf(],&stu[i].grade[],&stu[i].grade[]);
stu[i].grade[]=(stu[i].grade[]+stu[i].grade[]+stu[i].grade[])/3.0;
}
;now<;now++){
sort(stu,stu+n,cmp);
Rank[stu[].id][now]=;
;i<n;i++){
].grade[now]){
Rank[stu[i].id][now]=Rank[stu[i-].id][now];
}
else{
Rank[stu[i].id][now]=i+;
}
}
}
int queryid;
;i<m;i++){
scanf("%d",&queryid);
]==){
printf("N/A\n");
}
else{
;
;j<;j++){
if(Rank[queryid][j]<Rank[queryid][best]){
best=j;
}
}
printf("%d %c\n",Rank[queryid][best],course[best]);
}
}
;
}
1012 The Best Rank (25 分)的更多相关文章
- 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 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- 1012 The Best Rank (25 分)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- 【PAT甲级】1012 The Best Rank (25 分)
题意: 输入两个整数N,M(<=2000),接着分别输入N个学生的ID,C语言成绩,数学成绩和英语成绩. M次询问,每次输入学生ID,如果该ID不存在则输出N/A,存在则输出该学生排名最考前的一 ...
- 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. The Best Rank (25)
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...
- 1012. The Best Rank (25)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- 1012 The Best Rank (25)(25 point(s))
problem To evaluate the performance of our first year CS majored students, we consider their grades ...
- PAT-1012 The Best Rank (25 分) 查询分数对应排名(包括并列)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT (Advanced Level) 1012. The Best Rank (25)
简单排序题. 注意:分数相同的人排名相同. #include<iostream> #include<cstring> #include<cmath> #includ ...
随机推荐
- mysql sum(if())用法
原表:id fenlei time1 分类1 201303162 分类2 201303163 分类3 201303174 ...
- videojs 隐藏videobar
video::-internal-media-controls-download-button { display: none; } video::-webkit-media-controls-enc ...
- Redis 缓存服务器
Redis 服务器 Remote Dictionay Server Redis是一个key-value持久化产品,通常被称为数据结构服务器. Redis的key是string类型:value可以是 ...
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程
Himi 原创, 欢迎转载,转载请在明显处注明! 谢谢. 原文地址:http://blog.csdn.net/xiaominghimi/article/details/6937097 //——201 ...
- opencv-python教程学习系列2-读取/显示/保存图像
前言 opencv-python教程学习系列记录学习python-opencv过程的点滴,本文主要介绍图像的读取.显示以及保存,坚持学习,共同进步. 系列教程参照OpenCV-Python中文教程: ...
- jQuery--- .hasOwnProperty 用法
☆ obj.hasOwnProperty('prop'): 是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是, 此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个 ...
- grandstack graphql 工具基本试用
grandstack 是一个方便graphql 应用开发的工具 使用docker-compose 运行 环境准备 官方的starter 比较好,已经是使用docker-compose 创建好了所有 ...
- WebApi_基于Token的身份验证——JWT
JWT是啥? JWT就是一个字符串,经过加密处理与校验处理的字符串,形式为: A.B.C A由JWT头部信息header加密得到B由JWT用到的身份验证信息json数据加密得到C由A和B加密得到,是校 ...
- PHP中数组的各种用法
$a = 'false';if($a){ echo '好坑';}输出好坑,得转换成布尔值才行哦. in_array $people = array("Bill", "St ...
- Mysql监控调优
提升性能 1.允许情况下,调大连接数 2.开启查询缓存(看命中率,用在变化不大的表内) 3.锁(查看是否存在死锁) 4.慢查询(将执行时间过长的语句写入日志内) 5.explain(分析表结构,typ ...