1141. PAT Ranking of Institutions (25)
1141. PAT Ranking of Institutions (25)
After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (<=105), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:
ID Score School
where “ID” is a string of 6 characters with the first one representing the test level: “B” stands for the basic level, “A” the advanced level and “T” the top level; “Score” is an integer in [0, 100]; and “School” is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that “ID” is unique for each testee.
Output Specification:
For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:
Rank School TWS Ns
where “Rank” is the rank (start from 1) of the institution; “School” is the institution code (all in lower case); “TWS” is the total weighted score which is defined to be the integer part of “ScoreB/1.5 + ScoreA + ScoreT×1.5”, where “ScoreX” is the total score of the testees belong to this institution on level X; and “Ns” is the total number of testees who belong to this institution.
The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.
【数据】
Sample Input:
10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypuSample Output:
5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2
【分析】
题意很简单,给出每个选手的ID,分数,学校,ID第一位表示该学生参加的难度,然后将每个学校的每个级别的所有参赛选手总分记录后按照
A + B/1.5 + T×1.5 的公式计算后按总分降序排序,若分数相同则看这个学校的参赛人数,按参赛人数升序排列,若人数也相同则将学校名称按字典序从小到大排序
有个小问题就是这里的总分是the integer part of “ScoreB/1.5 + ScoreA + ScoreT×1.5” 所以是用double类型先计算然后再强转成int类型…其他貌似没什么大问题
【代码】
#include <bits/stdc++.h>
using namespace std;
struct XX{
int sc[5];
string name;
int number,score;
}ans[1000000];
map<string,int> ma;
bool cmp(const XX&x,const XX&y)
{
if (x.score != y.score) return x.score>y.score;
if (x.number != y.number) return x.number < y.number;
return x.name < y.name;
}
int main()
{
int n;scanf("%d",&n);//getchar();
ma.clear();
int len=1;
// memset(ans,0,sizeof(ans));
for (int i=0;i<n;i++)
{
char s[200],ss[200];
int score;
scanf("%s %d %s",s,&score,ss);
int id = -1;
if (s[0]== 'A' || s[0] =='a') id = 0;
if (s[0]== 'B' || s[0] =='b') id = 1;
if (s[0]== 'T' || s[0] =='t') id = 2;
int l = strlen(ss);
for (int j=0;j<l;j++)
if (ss[j]>='A' && ss[j]<='Z')
ss[j]+=32;
string x = ss;
//if (score<0 || score > 100 || id == -1) continue;
if (!ma.count(x))
{
ma[x]=len;
ans[len].name=x;
ans[len].sc[0]=ans[len].sc[1]=ans[len].sc[2] = 0;
ans[len].number= 0;
len++;
}
int idd=ma[x];
ans[idd].sc[id]+=score;
ans[idd].number++;
}
for (int i=1;i<len;i++)
{
double ss = 1.0*ans[i].sc[0] + 1.0*ans[i].sc[1]/1.5 + 1.0 * ans[i].sc[2] *1.5;
ans[i].score = (int)ss;
}
sort(ans+1,ans+len,cmp);
printf("%d\n",len-1);
int now = 1;
ans[0].score = -1;
for (int i=1;i<len;i++)
{
if (ans[i].score!=ans[i-1].score) now = i;
printf("%d ",now);
cout<<ans[i].name;
printf(" %d %d\n",ans[i].score,ans[i].number);
//printf("%d %s %d %d\n",now,ans[i].name.c_str(),ans[i].score,ans[i].number);
}
return 0;
}