现在,要给 CS 专业一年级的学生进行成绩评估。
我们只考虑他们的三门成绩:C
–c语言,M
–数学,E
–英语,除此之外,我们还会考虑 A
–三门成绩平均值。
注意:平均成绩为三科成绩平均值四舍五入取整的结果。
例如,四个学生的成绩单如下:
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
每个学生都会有各科排名以及平均成绩排名,我们通过强调学生的最佳成绩来鼓励学生。
因此,每个学生的成绩单上只会有四个成绩中排名最高的那个成绩的排名,以及具体是哪项成绩(C、M、E、AC、M、E、A 中的一项)。
例如,第一个学生的成绩单上会显示 1 C
,因为他的C语言排名第 11,这是他的最佳名次。
而第四个学生的成绩单上会显示 1 A
,因为他的平均成绩排名第 11,这是他的最佳名次。
输入格式
第一行包含两个整数 N,MN,M,分别表示学生总数和查询成绩单次数。
接下来 NN 行,每行首先包含一个由六位数字组成的学生 ID,然后包含三个整数分别表示该学生的 C,M,EC,M,E 三科成绩。
接下来 MM 行,每行包含一个学生 ID,表示要查询该学生的成绩单。
输出格式
对于每个学生,输出他的最佳排名以及该排名对应的是哪项成绩。
当多项排名相同,且都为最佳时,按照 A>C>M>EA>C>M>E 的优先级,选择输出哪项成绩。
如果无法查询到该学生的成绩,则输出 N/A
。
数据范围
1≤N,M≤20001≤N,M≤2000,
每科成绩均在 [0,100][0,100] 之间。
输入样例:
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
输出样例:
1 C
1 M
1 E
1 A
3 A
N/A
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cmath>
using namespace std;
const int N=2010;
unordered_map<string ,vector<int>>grade;
vector<int>q[4];
int get_rank(vector<int>&a,int x)
{
int pos=lower_bound(a.begin(),a.end(),x,greater<int>{})-a.begin();
return pos+1;
}
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
string id;
cin>>id;
int t[4]={0};
for(int j=1;j<=3;j++)
{
cin>>t[j];
t[0]+=t[j];
}
t[0]=round(t[0]/3.0);
for(int j=0;j<4;j++)
{
q[j].push_back(t[j]);
grade[id].push_back(t[j]);
}
}
for(int i=0;i<4;i++) sort(q[i].begin(),q[i].end(),greater<int>());
while(m--)
{
string s;
cin>>s;
string str="ACME";
if(!grade.count(s)) puts("N/A");
else
{
int res=0x3f3f3f;char c;
int rank;
for(int i=0;i<4;i++)
{
rank=get_rank(q[i],grade[s][i]);
if(rank<res)
{
res=rank;
c =str[i];
}
}
cout<<res<<" "<<c<<endl;
}
}
}