Recently, the ACM/ICPC team of Marjar University decided to choose some new members from freshmen to take part in the ACM/ICPC competitions of the next season. As a traditional elite university in ACM/ICPC, there is no doubt that application forms will fill up the mailbox. To constitute some powerful teams, coaches of the ACM/ICPC team decided to use a system to score all applicants, the rules are described as below. Please note that the score of an applicant is measured by pts, which is short for "points".
1. Of course, the number of solved ACM/ICPC problems of a applicant is important. Proudly, Marjar University have a best online judge system called Marjar Online Judge System V2.0, and in short, MOJ. All solved problems in MOJ of a applicant will be scored under these rules:
- (1) The problems in a set, called MaoMao Selection, will be counted as 2.5 pts for a problem.
- (2) The problems from Old Surgeon Contest, will be counted as 1.5 pts for a problem.
There is no problem in MaoMao Selection from Old Surgeon Contest.
- (3) Besides the problem from MaoMao Selection and Old Surgeon Contest, if the problem's id is a prime, then it will be counted as 1 pts.
- (4) If a solved problem doesn't meet above three condition, then it will be counted as 0.3 pts.
2. Competitions also show the strength of an applicant. Marjar University holds the ACM/ICPC competition of whole school once a year. To get some pts from the competition, an applicant should fulfill rules as below:
- The member of a team will be counted as 36 pts if the team won first prize in the competition.
- The member of a team will be counted as 27 pts if the team won second prize in the competition.
- The member of a team will be counted as 18 pts if the team won third prize in the competition.
- Otherwise, 0 pts will be counted.
3. We all know that some websites held problem solving contest regularly, such as JapanJam, ZacaiForces and so on. The registered member of JapanJam will have a rating after each contest held by it. Coaches thinks that the third highest rating in JapanJam of an applicant is good to show his/her ability, so the scoring formula is:
Here r is the third highest rating in JapanJam of an applicant.
4. And most importantly - if the applicant is a girl, then the score will be added by 33 pts.
The system is so complicated that it becomes a huge problem for coaches when calculating the score of all applicants. Please help coaches to choose the best M applicants!
Input
There are multiple test cases.
The first line of input is an integer T (1 ≤ T ≤ 10), indicating the number of test cases.
For each test case, first line contains two integers N (1 ≤ N ≤ 500) - the number of applicants and M (1 ≤ M ≤ N) - the number of members coaches want to choose.
The following line contains an integer R followed by R (0 ≤ R ≤ 500) numbers, indicating the id of R problems in MaoMao Selection.
And then the following line contains an integer S (0 ≤ S ≤ 500) followed by S numbers, indicating the id of S problems from Old Surgeon Contest.
The following line contains an integer Q (0 ≤ Q ≤ 500) - There are Q teams took part in Marjar University's competition.
Following Q lines, each line contains a string - team name and one integer - prize the team get. More specifically, 1 means first prize, 2 means second prize, 3 means third prize, and 0 means no prize.
In the end of each test case, there are N parts. In each part, first line contains two strings - the applicant's name and his/her team name in Marjar University's competition, a char sex - M for male, F for female and two integers P (0 ≤ P ≤ 1000) - the number of problem the applicant solved, C (0 ≤ C ≤ 1000) - the number of competitions the applicant have taken part in JapanJam.
The following line contains P integers, indicating the id of the solved problems of this applicant.
And, the following line contains C integers, means the rating for C competitions the applicant have taken part in.
We promise:
- The problems' id in MaoMao Selection, Old Surgeon Contest and applicant's solving list are distinct, and all of them have 4 digits (such as 1010).
- All names don't contain spaces, and length of each name is less than 30.
- All ratings are non-negative integers and less than 3500.
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct que
{
char qname[501];
int prize;
}qnum[501];
struct hum
{
double score;
char name[501],qname[501];
char sex;
int id[1001];
int rate[1001];
}humm[501];
int n,m;
int r,s;
int maomaonum[1001];
int surgeon[1001];
bool Cmp(int a,int b)
{
return a>b;
}
int prime(int n)
{
for(int i=2;i*i<=n;i++)
if(n%i==0)return 0;
return 1;
}
int cheakmao(int id)
{
for(int i=0;i<r;i++)
{
if(maomaonum[i]==id)
return 1;
}
return 0;
}
int cheaksur(int id)
{
for(int i=0;i<s;i++)
{
if(surgeon[i]==id)
return 1;
}
return 0;
}
bool cmp(hum a,hum b) //排序
{
if(fabs(a.score-b.score)<1e-8)
{
if(strcmp(a.name,b.name)<0)
return true;
else
return false;
}
if(a.score>b.score)
return true;
return false;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
scanf("%d",&r);
int i;
memset(maomaonum,0,sizeof(maomaonum));
memset(surgeon,0,sizeof(surgeon));
for(i=0;i<r;i++)
{
scanf("%d",&maomaonum[i]);
}
scanf("%d",&s);
for(i=0;i<s;i++)
{
scanf("%d",&surgeon[i]);
}
int cas;
scanf("%d",&cas);
for(i=0;i<cas;i++)
{
scanf("%s %d",qnum[i].qname,&qnum[i].prize);
}
int idnum,ranum;
int j;
for(i=0;i<n;i++)
{
scanf("%s%s %c%d%d",humm[i].name,humm[i].qname,&humm[i].sex,&idnum,&ranum);
humm[i].score=0.0;
for(j=0;j<idnum;j++)
{
scanf("%d",&humm[i].id[j]);
if(cheakmao(humm[i].id[j]))
{
humm[i].score+=2.5;
}
else if(cheaksur(humm[i].id[j]))
{
humm[i].score+=1.5;
}
else if(prime(humm[i].id[j]))
{
humm[i].score+=1.0;
}
else
{
humm[i].score+=0.3;
}
}
for(j=0;j<ranum;j++)
{
scanf("%d",&humm[i].rate[j]);
}
if(ranum>=3)
{
sort(humm[i].rate,humm[i].rate+ranum,Cmp);
if(humm[i].rate[2]>1200)
humm[i].score+=(humm[i].rate[2]-1200)*1.0/100*1.5; //注意这里*1.0
else
humm[i].score+=0;
}
else
humm[i].score+=0;
if(humm[i].sex=='F')
{
humm[i].score+=33;
}
for(j=0;j<cas;j++)
{
if(strcmp(humm[i].qname,qnum[j].qname)==0)
{
if(qnum[j].prize==1)
{
humm[i].score+=36;
}
else if(qnum[j].prize==2)
{
humm[i].score+=27;
}
else if(qnum[j].prize==3)
{
humm[i].score+=18;
}
else break;
}
}
}
sort(humm,humm+n,cmp);
for(i=0;i<m;i++)
{
printf("%s %0.3lf\n",humm[i].name,humm[i].score);
}
}
return 0;
}