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道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...
随机推荐
- 使用tuple统计文件中单词的个数
name = input("Enter file:") if len(name) < 1 : name = "input.txt" fhand = ope ...
- Codeforces#514E(贪心,并查集)
#include<bits/stdc++.h>using namespace std;long long w[100007],sum[100007];int fa[100007],degr ...
- 2017-11-7 NOIP模拟赛
1.数学老师的报复 #include<iostream> #include<cstdio> using namespace std; int cnt; ]; long long ...
- 分层图最短路 【bzoj1579】[Usaco2009 Feb]Revamping Trails 道路升级
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Description 每天,农夫John需要经过一些道路去检查牛棚N里面的牛. 农场上有M(1<=M< ...
- winform中的Datagridview控件与List同步修改
Winform的datagridview是个很强大的控件,可用datatable, List等型的数据与之绑定显示. 可惜的是,绑定的LIst不能同步更新. 估计是为了改进List不能同步更新的问题, ...
- 洛谷 P1892 [BOI2003]团伙(并查集)
嗯... 题目链接:https://www.luogu.org/problemnew/show/P1892 通过读题可以很清楚的发现这是一个并查集的题,并且要有两个集合: 若他们p和q是朋友,则存入第 ...
- 禁止tableview 像上滑动
tableView有一个bounces属性.默认YES,所以tableView上下用力拉都会有弹性滑动,如下设置可以禁止,但是这样的话上下弹性都没了 而经常的需求是上方不要弹性,下方要弹性,可以用监听 ...
- PIE使IE浏览器支持CSS3属性(圆角、阴影、渐变)
http://www.360doc.com/content/12/1214/09/11181348_253939277.shtml PIE使IE浏览器支持CSS3属性(圆角.阴影.渐变) 2012-1 ...
- PHP var_export
var_export可以将一个数组转为一个字符串 不同于var_dump,var_export并不会输出数据的类型以及字符大小等,只会简单把数组的key跟value拼接成一个字符串 <?php ...
- Silverlight Telerik 学习之主题的设置
Telerik控件版本:RadControls for Silverlight Q1 2013 当前的Telerik Silverlight 控件支持以下主题 Office Black - 这是默认主 ...