Source:

PAT A1012 The Best Rank (25 分)

Description:

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 (≤), 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 CMand 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

Keys:

  • 模拟题

Attention:

  • 拿原数组排序去了,找错误找了半天,脑壳疼0,0

Code:

 /*
Data: 2019-07-17 20:25:53
Problem: PAT_A101#The Best Rank
AC: 49:52 题目大意:
排名
输入:
第一行给出,学生总数N<=2e3,查询数M<=2e3
接下来N行,id,c,m,e
接下来M行,id
输出:
最好成绩,相应科目A>C>M>E
不存在N/A
*/ #include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e4,H=1e7,N=;
struct node
{
int id;
int grade[N],rnk[N];
}info[M];
int mp[H]={},st[M],key;
char sub[N]={'A','C','M','E'}; bool cmp(const int &a, const int &b)
{
return info[a].grade[key] > info[b].grade[key];
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,m,r,id;
scanf("%d%d", &n,&m);
for(int i=; i<=n; i++)
{
scanf("%d",&info[i].id);
mp[info[i].id]=i;
st[i]=i;
for(int j=; j<N; j++)
scanf("%d", &info[i].grade[j]);
info[i].grade[]=info[i].grade[]+info[i].grade[]+info[i].grade[];
}
for(int i=; i<N; i++)
{
key=i;
sort(st+,st+n+,cmp);
for(int j=; j<=n; j++)
{
int pre=st[j-],now=st[j];
if(j== || info[pre].grade[i]!=info[now].grade[i])
r=j;
info[now].rnk[i]=r;
}
}
for(int i=; i<m; i++)
{
scanf("%d", &id);
if(mp[id]==)
{
printf("N/A\n");
continue;
}
int best=;
for(int j=; j<N; j++)
if(info[mp[id]].rnk[j]<info[mp[id]].rnk[best])
best=j;
printf("%d %c\n", info[mp[id]].rnk[best],sub[best]);
} return ;
}

PAT_A1012#The Best Rank的更多相关文章

  1. UVA, 10336 Rank the Languages

    难点在于:递归函数和输出: #include <iostream> #include <vector> #include <algorithm> #include ...

  2. [LeetCode] Rank Scores 分数排行

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  3. rank()函数的使用

    排序: ---rank()over(order by 列名 排序)的结果是不连续的,如果有4个人,其中有3个是并列第1名,那么最后的排序结果结果如:1 1 1 4select scoreid, stu ...

  4. [转]oracle分析函数Rank, Dense_rank, row_number

    oracle分析函数Rank, Dense_rank, row_number 分析函数2(Rank, Dense_rank, row_number)   目录 ==================== ...

  5. 分区函数Partition By的与row_number()的用法以及与排序rank()的用法详解(获取分组(分区)中前几条记录)

    partition by关键字是分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition by用于给结果集分组,如果没有指 ...

  6. Learning to rank 介绍

    PS:文章主要转载自CSDN大神hguisu的文章"机器学习排序":          http://blog.csdn.net/hguisu/article/details/79 ...

  7. R语言排序:sort(),rank(),order()示例

    > x<-c(97,93,85,74,32,100,99,67) > sort(x) [1] 32 67 74 85 93 97 99 100 > order(x) [1] 5 ...

  8. [Machine Learning] Learning to rank算法简介

    声明:以下内容根据潘的博客和crackcell's dustbin进行整理,尊重原著,向两位作者致谢! 1 现有的排序模型 排序(Ranking)一直是信息检索的核心研究问题,有大量的成熟的方法,主要 ...

  9. sqlserver 中row_number,rank,dense_rank,ntile排名函数的用法

    1.row_number() 就是行号 2.rank:类似于row_number,不同之处在于,它会对order by 的字段进行处理,如果这个字段值相同,那么,行号保持不变 3.dense_rank ...

随机推荐

  1. 框架-.NET:.NET Core

    ylbtech-框架-.NET:.NET Core .NET Core是适用于 windows.linux 和 macos 操作系统的免费.开源托管的计算机软件框架,是微软开发的第一个官方版本,具有跨 ...

  2. 全局配置一个ajax的错误监控

    全局配置一个ajax的错误监控,比如$(document).ajaxError(function(evt, req, settings){    if(req && (req.stat ...

  3. The Preliminary Contest for ICPC Asia Shanghai 2019 (B L )

    B. Light bulbs 思路:差分 + 离散化, 好不容易懂了差分却没想到离散化,还是要罗老板出马..... AC代码: #include<bits/stdc++.h> using ...

  4. 部署项目问题(maven打包jar不对应,导致启动时一直找不到某个类)

    项目是springboot+maven  打包用maven的插件package 下面是打包后的目录结构  project-1.0 和project-1.0.tar.gz是一样的  区别就是一个是压缩包 ...

  5. cesium左侧列表定位目标

    cesium左侧列表定位目标 功能:根据左侧列表经纬度等信息的值,进行搜索定位. 列表: 1  点击清除按钮可以清空所有input的值 2  点击查找可以定位到位置,如果输入的值不在范围内,会有弹出框 ...

  6. Spring快速开启计划任务

    Spring3.1开始让计划任务变得非常简单,只需要几个注解就能快速开启计划任务的支持. @EnableScheduling @Target(ElementType.TYPE) @Retention( ...

  7. es7 async 前置依赖

    https://stackoverflow.com/questions/33527653/babel-6-regeneratorruntime-is-not-defined 移动端 px2rem-lo ...

  8. python之字符串中插入变量

    方法一:也是 比较好用的,功能教齐全 s="{name} is {sex}" print(s.format(name="zzy",sex="girl& ...

  9. sed以及awk

    一.sed sed是一种流编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时 缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的 内容,处理完成后,把缓 ...

  10. 发现最新版百度Android 定位SDK v6.1.3 网络定位bug

    对于百度地图已经实在忍无可忍了,实验室两年以前的一个项目用到了百度地图,以前师兄毕业了,我来维护这个破项目,百度地图推出新版本出来后,老版本的api不能用了,不能做到向下兼容吗?换掉少量的api也就算 ...