用map来记录每一个 athlete对应的分数集合,排序算出weighted sum。之后再将所有的athlete按照分数和name排序输出即可。
WA了好久o(╯□╰)o结果是样例看错了,并列排名的下一个rank并不是并列的rank+1。/(ㄒoㄒ)/~~连样例都能看错,没救了。T^T
以及athlete的个数最大是N*P,并不是maxn。
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
//2016 Round C Problem A. gRanks
int T;
const int maxn=110;
int N;
int M;
int P;
int S[maxn];
int W[maxn];
//string name[maxn][maxn];
string name;
map<string,vector<int> >mp;//map name to the weighted scores
pair<string,int>lst[maxn*maxn];
bool cmp(pair<string,int>a, pair<string,int>b)
{
if(a.second==b.second)
{
return a.first<b.first;
}
return a.second>b.second;
}
int main()
{
freopen("A-large-practice.in","r",stdin);
// freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&T);
for(int ca=1;ca<=T;ca++)
{
memset(S,0,sizeof(S));
memset(W,0,sizeof(W));
//memset(lst,0,sizeof(lst)); cause run time error
mp.clear();
//cout<<mp.size()<<endl;
scanf("%d",&P);
for(int i=0;i<P;i++)
{
scanf("%d",&S[i]);
}
scanf("%d",&N);
for(int i=0;i<N;i++)
{
scanf("%d",&W[i]);
for(int j=0;j<P;j++)
{
cin>>name;
mp[name].push_back(W[i]*S[j]);
}
}
scanf("%d",&M);
map<string,vector<int> >::iterator iter;
int cnt=0;
for(iter=mp.begin();iter!=mp.end();iter++)
{
// cout<<iter->first<<" "<<iter->second.size()<<endl;
int sum=0;
sort(iter->second.begin(),iter->second.end(),greater<int>());
int sz=(int)iter->second.size();
for(int i=0;i<min(M,sz);i++)
{
// cout<<iter->second[i]<<endl;
sum+=iter->second[i];
}
// cout<<sum<<" "<<cnt<<endl;
lst[cnt++]=make_pair(iter->first,sum);
}
sort(lst,lst+cnt,cmp);
int rak=1;
printf("Case #%d:\n",ca);
for(int i=0;i<cnt;i++)
{
if(i!=0&&lst[i].second<lst[i-1].second)
{
//cout<<i<<" "<<rak<<endl;
rak=i+1;
}
cout<<rak<<": "<<lst[i].first<<endl;
}
}
return 0;
}