題目鏈接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3705
思路
算是比較簡單的模擬題吧,題意太長就不講了。
比賽時是最後的時間做這題的,結果看太快了沒看到分數相同時要按名字字母順序排,導致WA到最後。
後來debug時想着按分數增序然後輸出後m個,結果比較名字時寫的還是小於導致名字成增序,逆着輸出就是降序了,於是又debug了好久。果然細心好重要。
AC代碼
#include <bits/stdc++.h>
using namespace std;
int prm[100000];
const int MAXV = 10000;
bool isPrime[MAXV+1];
int size=0;
void getPrime()
{
memset(isPrime, true, sizeof(isPrime));
int sq = sqrt((double)MAXV) + 1;
int i,j,k;
for(i = 2;i <= sq; i++)
if(isPrime[i])
for(j = 2,k = MAXV/i+1;j < k;j++)
isPrime[i*j] = false;
for( i = 2 ; i <= MAXV; i++)
if(isPrime[i])
prm[size++] = i;
isPrime[0] = isPrime[1] = false;
}
map<int,double>problem;
map<string,double>contest;
struct node
{
string name;
double score;
}
app[600];
bool cmp(node a, node b)
{
if(fabs(a.score-b.score)<1e-6)
return a.name<b.name;
return a.score>b.score;
}
int main()
{
getPrime();
int T;
cin>>T;
while(T--)
{
problem.clear();
contest.clear();
int n,m;
cin>>n>>m;
int r,s;
cin>>r;
for(int i=0 ; i<r ; ++i)
{
int t;
cin>>t;
problem[t]=2.5;
}
cin>>s;
for(int i=0 ; i<s ; ++i)
{
int t;
cin>>t;
if(!problem.count(t))
problem[t]=1.5;
}
int q;
cin>>q;
for(int i=0 ; i<q ; ++i)
{
string name;
int num;
cin>>name>>num;
int score=0;
if(num==1)score=36;
else if(num==2)score=27;
else if(num==3)score=18;
if(score)contest[name]=score;
}
for(int i=0 ; i<n ; ++i)
{
string name1,name2,sex;
int p,c;
cin>>name1>>name2>>sex>>p>>c;
app[i].name=name1;
app[i].score=0;
if(contest.count(name2))
app[i].score+=contest[name2];
if(sex=="F")app[i].score+=33;
for(int j=0 ; j<p ; ++j)
{
int id;
cin>>id;
if(problem.count(id))app[i].score+=problem[id];
else if(isPrime[id])app[i].score+=1;
else app[i].score+=0.3;
}
int rating[2000]={0};
for(int j=0 ; j<c ; ++j)
{
cin>>rating[j];
}
sort(rating,rating+c);
if(c>=3)
app[i].score+=max(0.0,(rating[c-3]-1200.0)/100*1.5);
}
sort(app,app+n,cmp);
for(int i=0 ; i<m ; ++i)
{
cout<<app[i].name<<" ";
cout<<fixed<<setprecision(3);
cout<<app[i].score<<"\n";
}
}
return 0;
}