PAT_A1012#The Best Rank
Source:
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), andE
- 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
andA
- 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
andE
. 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的更多相关文章
- UVA, 10336 Rank the Languages
难点在于:递归函数和输出: #include <iostream> #include <vector> #include <algorithm> #include ...
- [LeetCode] Rank Scores 分数排行
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- rank()函数的使用
排序: ---rank()over(order by 列名 排序)的结果是不连续的,如果有4个人,其中有3个是并列第1名,那么最后的排序结果结果如:1 1 1 4select scoreid, stu ...
- [转]oracle分析函数Rank, Dense_rank, row_number
oracle分析函数Rank, Dense_rank, row_number 分析函数2(Rank, Dense_rank, row_number) 目录 ==================== ...
- 分区函数Partition By的与row_number()的用法以及与排序rank()的用法详解(获取分组(分区)中前几条记录)
partition by关键字是分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition by用于给结果集分组,如果没有指 ...
- Learning to rank 介绍
PS:文章主要转载自CSDN大神hguisu的文章"机器学习排序": http://blog.csdn.net/hguisu/article/details/79 ...
- 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 ...
- [Machine Learning] Learning to rank算法简介
声明:以下内容根据潘的博客和crackcell's dustbin进行整理,尊重原著,向两位作者致谢! 1 现有的排序模型 排序(Ranking)一直是信息检索的核心研究问题,有大量的成熟的方法,主要 ...
- sqlserver 中row_number,rank,dense_rank,ntile排名函数的用法
1.row_number() 就是行号 2.rank:类似于row_number,不同之处在于,它会对order by 的字段进行处理,如果这个字段值相同,那么,行号保持不变 3.dense_rank ...
随机推荐
- JS-动态加载
var s = document.createElement('script'); s.setAttribute('src', ''); s.setAttribute('type', 'text/ja ...
- Kafka启动报错
文章目录 问题 解决 问题 通过 ./kafka-server-start.sh ../config/server.properties 启动kafka 之前在server.properties中修改 ...
- HDU6655 Just Repeat(2019杭电多校J题)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 简单博弈问题,A,B手里各有n,m张牌,牌有颜色,两人轮流出牌(A先出),一个人只能打出对放未打 ...
- 力扣算法题—144Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3 ...
- Java对象toString()方法
对象的字符串表示以可读格式包含有关对象状态的信息.Object类的toString()方法表示字符串中类的对象.Object类提供了toString()方法的默认实现. 它返回一个以下格式的字符串: ...
- jmeter 响应超时时间设置 压力增大,不能正常退出全部线程
当压力增大会出现connect timeout error 压力增大,不能正常退出全部线程: 解决办法:http request default--advance--timeouts 如填写1,表示大 ...
- python3中浮点数相减问题(大部分时候只需要关注整数的二进制形式就行了)
首先直接上判断方法:一切判断直接将整数部分装化成二进制,如果位数相等则相减后的值是等于的,如果不相等,相减大的结果一定不等于你要比较的结果. 如66.6-60.6==6.0的情况,66.6的二进制:1 ...
- JUnit中Assert简单介绍
junit中的assert方法全部放在Assert类中,总结一下junit类中assert方法的分类.1.assertTrue/False([String message,]boolean condi ...
- .net微信扫码支付
今天给大家分享一篇.net的扫码支付文章,话不多说直接进入主题. 如有需要可以加我Q群[308742428]大家一起讨论技术,有偿服务. 后面会不定时为大家更新文章,敬请期待. 喜欢的朋友可以关注下. ...
- 防御 CSRF
我还针对这个问题请教了 @c4605 , 他对防御 CSRF 提出了两种解决方案: 在每个表单中包含一个 CSRF Token.不将用于认证的 Token 或 Seesion ID 储存在 Cooki ...