PAT甲题题解-1012. The Best Rank (25)-排序水题
排序,水题
因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E
那么按这个优先级顺序进行排序
每次排序前先求当前课程的排名
然后再与目前最好的排名比较、更新
至于查询,建立id与索引的映射即可。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn=+;
int n,m;
map<string,int> maps;
struct Stu{
char id[];
int score[];
int ranks;
int best_rank=;
int c;
}stu[maxn]; bool cmp1(Stu a,Stu b){
return a.score[]>b.score[];
}
bool cmp2(Stu a,Stu b){
return a.score[]>b.score[];
}
bool cmp3(Stu a,Stu b){
return a.score[]>b.score[];
}
bool cmp4(Stu a,Stu b){
return a.score[]>b.score[];
} void solveRanks(int k){
stu[].ranks=;
if(stu[].ranks<stu[].best_rank){
stu[].best_rank=stu[].ranks;
stu[].c=k;
}
for(int i=;i<n;i++){
if(stu[i].score[k]==stu[i-].score[k]){
stu[i].ranks=stu[i-].ranks;
}
else{
stu[i].ranks=i+;
}
if(stu[i].ranks<stu[i].best_rank){
stu[i].best_rank=stu[i].ranks;
stu[i].c=k;
}
}
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=;i<n;i++){
scanf("%s %d %d %d",stu[i].id,&stu[i].score[],&stu[i].score[],&stu[i].score[]);
stu[i].score[]=(stu[i].score[]+stu[i].score[]+stu[i].score[])/;
}
sort(stu,stu+n,cmp4);
solveRanks(); sort(stu,stu+n,cmp1);
solveRanks(); sort(stu,stu+n,cmp2);
solveRanks(); sort(stu,stu+n,cmp3);
solveRanks(); string str;
for(int i=;i<n;i++){
str=stu[i].id;
maps[str]=i+;
}
char course[]={'C','M','E','A'};
for(int i=;i<m;i++){
cin>>str;
int idx=maps[str]-;
if(idx==-)
printf("N/A\n");
else
printf("%d %c\n",stu[idx].best_rank,course[stu[idx].c]);
}
return ;
}
PAT甲题题解-1012. The Best Rank (25)-排序水题的更多相关文章
- PAT甲题题解-1062. Talent and Virtue (25)-排序水题
水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚
n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...
- PAT甲题题解-1052. Linked List Sorting (25)-排序
三个注意点: 1.给出的n个节点并不一定都在链表中 2.最后一组样例首地址即为-1 3.输出地址的时候一直忘记前面要补0... #include <iostream> #include & ...
- 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 ...
- 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甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题
题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...
- PAT甲题题解-1058. A+B in Hogwarts (20)-大水题
无语,这种水题还出,浪费时间,但又不得不A... #include <iostream> #include <cstdio> #include <algorithm> ...
- HDU排序水题
1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...
随机推荐
- 乘风破浪:LeetCode真题_041_First Missing Positive
乘风破浪:LeetCode真题_041_First Missing Positive 一.前言 这次的题目之所以说是难,其实还是在于对于某些空间和时间的限制. 二.First Missing Posi ...
- 翻译:使用红外传感器与Arduino进行简单动作与手势检测
译注:昨天看 Adruino 的 Twitter 推了这篇项目,第一眼就觉得非常有趣,翻译给大家看看.文中的红外传感器比较高级,和淘宝上5块钱的那种只能输出0和1的不一样, TPA81 是可以输出温度 ...
- SQL SERVER 2005镜像配置(有无见证服务器都行)
我用的是没有见证的,但找的文章里有镜像,所以都做一下补充,两个网址做的参考, 之所以在从他们那再补充一次是为了怕有一天他们的文章被删了我这还有个备用的,这两篇写的不错 其他的都不行 特别乱,这是找的最 ...
- python第三十四课——2.匿名函数配合容器函数的使用
匿名函数配合容器函数的使用(了解) 1.匿名函数配合列表对象使用 lt=[lambda x:x**2,lambda x:x**3,lambda x:x**4] for i in lt: print(i ...
- BZOJ4556:[TJOI\HEOI2016]字符串(后缀数组,主席树,二分,ST表)
Description 佳媛姐姐过生日的时候,她的小伙伴从某东上买了一个生日礼物.生日礼物放在一个神奇的箱子中.箱子外边写了一个长为n的字符串s,和m个问题.佳媛姐姐必须正确回答这m个问题,才能打开箱 ...
- BZOJ5102:[POI2018]Prawnicy(贪心,堆)
Description 定义一个区间(l,r)的长度为r-l,空区间的长度为0. 给定数轴上n个区间,请选择其中恰好k个区间,使得交集的长度最大. Input 第一行包含两个正整数n,k(1<= ...
- 【转】ios tableView那些事(一)创建一个简单的tableView
工作也有半年多了!几乎每个项目中的会用到tableview这个神奇而好用的控件,在学习和工作中都会看别人的博客!对我有很大的帮助,就如同站在巨人的肩膀上的感觉吧 哈哈!于是决定重新开始写博客,希望能帮 ...
- Scala学习之路 (二)使用IDEA开发Scala
目前Scala的开发工具主要有两种:Eclipse和IDEA,这两个开发工具都有相应的Scala插件,如果使用Eclipse,直接到Scala官网下载即可http://scala-ide.org/do ...
- windows下一根数据线玩转树莓派zero(w)
买了个树莓派zero w,想着用一根普通micro数据线达成 供电+ssh+通过usb共享网络+远程桌面 的目标 通过用静态ip免去了用benjour的连接不稳定方法,下面开始细说 需要的硬件: 树莓 ...
- numpy库数组拼接np.concatenate的用法
concatenate功能:数组拼接 函数定义:numpy.concatenate((a1, a2, ...), axis=0, out=None)