pat甲级1012
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的更多相关文章
- PAT甲级1012. The Best Rank
PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...
- PAT——甲级1012:The Best Rank(有坑)
1012 The Best Rank (25 point(s)) To evaluate the performance of our first year CS majored students, ...
- PAT 甲级 1012 The Best Rank
https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480 To evaluate the perfor ...
- PAT甲级1012题解——选择一种合适数据存储方式能使题目变得更简单
题目分析: 本题的算法并不复杂,主要是要搞清楚数据的存储方式(选择一种合适的方式存储每个学生的四个成绩很重要)这里由于N的范围为10^6,故选择结构体来存放对应下标为学生的id(N只有2000的范围, ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- PAT甲级——1012 The Best Rank
PATA1012 The Best Rank To evaluate the performance of our first year CS majored students, we conside ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级考前整理(2019年3月备考)之二,持续更新中.....
PAT甲级考前整理之一网址:https://www.cnblogs.com/jlyg/p/7525244.html,主要总结了前面131题的类型以及易错题及坑点. PAT甲级考前整理三网址:https ...
- PAT甲级考前整理(2019年3月备考)之一
转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...
随机推荐
- Spring深入学习
涨知识系列 Environment environment = context.getEnvironment(); 在Spring中所有被加载到spring中的配置文件都会出现在这个环境变量中, 其中 ...
- ABC118D(DP,完全背包,贪心)
#include<bits/stdc++.h>using namespace std;int cnt[10]={0,2,5,5,4,5,6,3,7,6};int dp[10007];int ...
- bzoj3876: [Ahoi2014&Jsoi2014]支线剧情(上下界费用流)
传送门 一道题让我又要学可行流又要学zkw费用流…… 考虑一下,原题可以转化为一个有向图,每次走一条路径,把每一条边都至少覆盖一次,求最小代价 因为一条边每走过一次,就要付出一次代价 那不就是费用流了 ...
- 解读人:刘佳维,Spectral Clustering Improves Label-Free Quantification of Low-Abundant Proteins(谱图聚类改善了低丰度蛋白的无标记定量)
发表时间:(2019年4月) IF:3.95 单位: 维也纳医科大学: 欧洲生物信息研究所(EMBL-EBI): 分子病理学研究所: 奥地利科学院分子生物技术研究所: Gregor Mendel分子植 ...
- JSONObject,JSONArray,String,Map间的互转
引言 在平常的Web项目开发过程中,json和String.map是最常用的类型和返回结果集,其中也经常会涉及到之间的各种相互转换,下边就总结一下: 1.String转JSONObject ...
- h5自定义播放器得实现原理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [HNOI2011]数学作业 矩阵快速幂 BZOJ 2326
题目描述 小 C 数学成绩优异,于是老师给小 C 留了一道非常难的数学作业题: 给定正整数 NNN 和 MMM ,要求计算Concatenate(1..N) Concatenate (1 .. N) ...
- 检测工具lynis
wget https://gitee.com/zzhlinux911218/software/raw/master/linux-inspect2.sh;bash linux-inspect2.sh检测 ...
- 洛谷P2184 贪婪大陆
题目背景 面对蚂蚁们的疯狂进攻,小FF的\(Tower\) \(defence\)宣告失败--人类被蚂蚁们逼到了\(Greed\) \(Island\)上的一个海湾.现在,小FF的后方是一望无际的大海 ...
- DSL与GPL
一.DSL 与 GPL DSL(Domain-Specified Language 领域特定语言),而与 DSL 相对的就是 GPL,最常见的 DSL 包括 Regex 以及 HTML & C ...