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. Linux C遇到的常见错误

    此随笔主要记录一些Linux C遇到的常见错误,便于debug问题或自己编程时,避免发生类似的错误或问题,后续会持续更新.... 1.内存泄露问题 内存泄露是由于内存没有释放导致程序耗内存一直增大,引 ...

  2. linux搭建集群

    磁盘分布 /boot 系统启动时需要的内存(200m) / 系统的可用磁盘大小(10240m) swap 交换内存 建议和内存一致(200m) 名字统一设置: 虚拟机名字 计算机名字 网络中的名字 默 ...

  3. JSHOP2

    JSHOP2是一个HTN(hierarchy task network)规划器,是SHOP2(simple hierarchy ordered planner )的java实现版本. SHOP2的官网 ...

  4. upc组队赛4 TV Show Game 【2-SAT】

    TV Show Game 题目描述 Mr. Dajuda, who is famous for a TV show program, occasionally suggests an interest ...

  5. (转)Adaboost

    基本原理 Adaboost算法基本原理就是将多个弱分类器(弱分类器一般选用单层决策树)进行合理的结合,使其成为一个强分类器. Adaboost采用迭代的思想,每次迭代只训练一个弱分类器,训练好的弱分类 ...

  6. 【react】---react中使用装饰器

    一.creact-react-app中使用装饰器 运行 npm run eject 可以让由create-react-app创建的项目的配置项暴露出来 此时,项目中多了一个config文件,并且各个配 ...

  7. python *arg和**kwargs的区别

    转载自:https://www.cnblogs.com/yunguoxiaoqiao/p/7626992.html 一.*args的使用方法 *args 用来将参数打包成tuple给函数体调用 举个栗 ...

  8. VC2008中处理CStatic控件的单击STN_CLICKED消息

    在MFC中,静态文本CStatic控件主要是用来作为标签,即作为注释用的.一般情况下不做消息响应.但是有时特殊情况下会做一些消息响应,比如处理单击事件STN_CLICKED等. 在VC2008下使用M ...

  9. USACO Milk Routing /// 优先队列广搜

    题目大意: 在n个点 m条边的无向图中 需要运送X单位牛奶 每条边有隐患L和容量C 则这条边上花费时间为 L+X/C 求从点1到点n的最小花费 优先队列维护 L+X/C 最小 广搜到点n #inclu ...

  10. Neo4j-Cypher查询语言-函数

    断言函数(Predicate functions)  函数名称 函数说明 ALL(identifier in collection WHERE predicate) 判断一个断言(predicate) ...