1012 The Best Rank (25)(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 Algebra), 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

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

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
由于C,M,E三科分数均为[0, 100]整数,因此可用数组cnt存储每个分数的人数,然后累加就可以得到每个分数对应的名次。
而平均分不是整数,先将平均分排序,然后用二分查找的方法找出其对应的名次。
 #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std; struct grade
{
int s[];
double A;
};
int cnt[][];
int cnt2[][]; int avgRank(vector<double> avg, double d); int main()
{
int n, m;
cin >> n >> m;
map<int, grade> mapp;
vector<double> avg; int id, i, j;
grade g;
for (i = ; i < n; i++)
{
cin >> id;
g.A = ;
for (j = ; j < ; j++)
{
cin >> g.s[j];
g.A += (double)g.s[j];
cnt[j][g.s[j]]++;
}
g.A /= ;
avg.push_back(g.A);
mapp[id] = g;
} cnt2[][] = cnt2[][] = cnt2[][] = ;
for (i = ; i >= ; i--)
{
for (j = ; j < ; j++)
cnt2[j][i] = cnt2[j][i + ] + cnt[j][i + ];
} sort(avg.begin(), avg.end()); int min, s, t;
char arr[] = { 'C', 'M', 'E', 'A' };
for (i = ; i < m; i++)
{
min = ;
cin >> id;
if (mapp.find(id) == mapp.end())
{
cout << "N/A" << endl;
continue;
}
for (j = ; j < ; j++)
{
t = cnt2[j][mapp[id].s[j]];
if ( t < min)
{
min = t;
s = j;
}
}
t = avgRank(avg, mapp[id].A);
if (t <= min)
{
min = t;
s = ;
}
cout << min << " " << arr[s] << endl;
}
return ;
} int avgRank(vector<double> avg, double d)
{
int mid = -, i = , j = avg.size() - ;
while (i <= j)
{
mid = (i + j) / ;
if (d > avg[mid])
i = mid + ;
else if (d == avg[mid])
break;
else
j = mid - ;
}
return avg.size() - mid;
}

提交时发现直接把平均分四舍五入取整也可以通过:

 #include <iostream>

 #include <map>
using namespace std; struct grade
{
int s[];
}; int cnt[][];
int cnt2[][]; int main()
{
int n, m;
cin >> n >> m;
map<int, grade> mapp; int id, i, j;
grade g;
for (i = ; i < n; i++)
{
cin >> id;
g.s[] = ;
for (j = ; j < ; j++)
{
cin >> g.s[j];
g.s[] += g.s[j];
cnt[j][g.s[j]]++;
}
g.s[] = g.s[] / 3.0 + 0.5;
cnt[][g.s[]]++;
mapp[id] = g;
} for (i = ; i < ; i++)
{
cnt2[i][] = ;
for (j = ; j >= ; j--)
cnt2[i][j] = cnt2[i][j + ] + cnt[i][j + ];
}
int min, s, t;
char arr[] = { 'A', 'C', 'M', 'E' };
for (i = ; i < m; i++)
{
min = ;
cin >> id;
if (mapp.find(id) == mapp.end())
{
cout << "N/A" << endl;
continue;
}
for (j = ; j < ; j++)
{
t = cnt2[j][mapp[id].s[j]];
if ( t < min)
{
min = t;
s = j;
}
}
cout << min << " " << arr[s] << endl;
}
return ;
}


pat甲级1012的更多相关文章

  1. PAT甲级1012. The Best Rank

    PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...

  2. PAT——甲级1012:The Best Rank(有坑)

    1012 The Best Rank (25 point(s)) To evaluate the performance of our first year CS majored students, ...

  3. PAT 甲级 1012 The Best Rank

    https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480 To evaluate the perfor ...

  4. PAT甲级1012题解——选择一种合适数据存储方式能使题目变得更简单

    题目分析: 本题的算法并不复杂,主要是要搞清楚数据的存储方式(选择一种合适的方式存储每个学生的四个成绩很重要)这里由于N的范围为10^6,故选择结构体来存放对应下标为学生的id(N只有2000的范围, ...

  5. PAT 甲级 1012 The Best Rank (25 分)(结构体排序)

    题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...

  6. PAT甲级——1012 The Best Rank

    PATA1012 The Best Rank To evaluate the performance of our first year CS majored students, we conside ...

  7. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  8. PAT甲级考前整理(2019年3月备考)之二,持续更新中.....

    PAT甲级考前整理之一网址:https://www.cnblogs.com/jlyg/p/7525244.html,主要总结了前面131题的类型以及易错题及坑点. PAT甲级考前整理三网址:https ...

  9. PAT甲级考前整理(2019年3月备考)之一

       转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...

随机推荐

  1. Protocol Buffers官方文档(开发指南)

    本文是对官方文档的翻译,然后截取了一篇非常优秀的文章片段来帮助理解,本人英文水平有限,基本都是直译,如果有不理解的地方请参考英文官方文档,参考的文章链接在文章末尾 protocol buffers简介 ...

  2. BK Componet Monitor

    Apache a) 启动服务前将监听地址改成0.0.0.0 b) 确认在文件“/etc/httpd/conf.modules.d/00-base.conf“中有加载mod_status模块 c) 新建 ...

  3. nginx 安装遇到的问题

    今天想学学 nginx,于是先把它安装起来.按照 http://nginx.org/en/linux_packages.html 上面的方法,在我的 ubuntu 虚拟机上很容易地就安装好了.可是要运 ...

  4. c/c++/c# 快速计算 Cumulative Normal Distribution 正态累积函数CDF

    链接: http://stackoverflow.com/questions/2328258/cumulative-normal-distribution-function-in-c-c http:/ ...

  5. ICP备案接入商

    1. 什么是ICP备案中的接入商 ICP备案系统中所说的接入商:是指为您提供虚拟主机.服务器托管或者专线接入的公司. 现在ICP备案的原则是“谁接入谁负责”,接入商一般都有自己的电子平台和工信部对接, ...

  6. 在Eclipse中使用Maven创建Web工程

    在Eclipse中使用Maven创建Web工程 1.创建maven Project工程,使用maven-archetype-webapp 2.在pom.xml文件中,设置打包类型为war <pa ...

  7. Jmeter 线程组、运行次数参数化(转)Jpara1=4 -Jpara2=5

    Jmeter的jmx文件保存了线程数和运行次数等参数,这个参数可以在命令行中传入参数的方式来修改数值 步骤如下 1.生成线程和运行次数的参数 Jmeter选项中函数助手对话框,选中__P参数,这个参数 ...

  8. POJ1028 Web Navigation

    题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...

  9. 怎么在Vue中使用Base64格式的背景

    问题发生于一次mock数据,生成了base64格式的东西,因为编码包在一个变量中,不知道怎么直接在 :style 中引入. 解答1:格式background-image: url(此处是我们mock生 ...

  10. Angular学习笔记【如何正确使用第三方组件】

    例如:ng-bootstrap的使用: 1.首先肯定是先要安装,参考官网给出的指令安装即可.(npm install --save @ng-bootstrap/ng-bootstrap) 2.在App ...