Applications http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5008
string set 专场
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<iostream> 5 #include<algorithm> 6 #include<set> 7 #define mt(a,b) memset(a,b,sizeof(a)) 8 using namespace std; 9 const double eps=1e-8; 10 const int M=10000; 11 set<int> A,B; 12 set<string> xiaosai[4]; 13 int defen[]={0,36,27,18}; 14 char op[32]; 15 struct G{ 16 double val; 17 string name; 18 friend bool operator <(const G &a,const G &b){ 19 return a.val>b.val||(fabs(a.val-b.val)<eps&&a.name<b.name); 20 } 21 }p[512]; 22 int pri[M],mark[M],pricnt;//mark[i]存i的最小因子,素数时mark[i]==i 23 void sieve_primes() { //筛素数 24 pricnt=0; 25 mt(mark,0); 26 mark[0]=mark[1]=1; 27 for(int i=2; i<M; i++) { 28 if(!mark[i]) pri[pricnt++]=mark[i]=i; 29 for(int j=0; pri[j]*i<M; j++) { 30 mark[i*pri[j]]=pri[j]; 31 if(!(i%pri[j])) break; 32 } 33 } 34 } 35 int rat[1024]; 36 int main(){ 37 sieve_primes(); 38 int t,n,m,q,c,tmp,id; 39 while(~scanf("%d",&t)){ 40 while(t--){ 41 scanf("%d%d%d",&n,&m,&q); 42 A.clear(); 43 while(q--){ 44 scanf("%d",&tmp); 45 A.insert(tmp); 46 } 47 scanf("%d",&q); 48 B.clear(); 49 while(q--){ 50 scanf("%d",&tmp); 51 B.insert(tmp); 52 } 53 scanf("%d",&q); 54 for(int i=0;i<4;i++){ 55 xiaosai[i].clear(); 56 } 57 while(q--){ 58 scanf("%s%d",op,&id); 59 xiaosai[id].insert((string)op); 60 } 61 for(int i=0;i<n;i++){ 62 p[i].val=0; 63 scanf("%s",op); 64 p[i].name=(string)op; 65 scanf("%s",op); 66 for(int j=1;j<=3;j++){ 67 if(xiaosai[j].count((string)op)){ 68 p[i].val+=defen[j]; 69 break; 70 } 71 } 72 scanf("%s",op); 73 if(op[0]=='F') p[i].val+=33; 74 scanf("%d%d",&q,&c); 75 while(q--){ 76 scanf("%d",&tmp); 77 if(A.count(tmp)){ 78 p[i].val+=2.5; 79 continue; 80 } 81 if(B.count(tmp)){ 82 p[i].val+=1.5; 83 continue; 84 } 85 if(mark[tmp]==tmp){ 86 p[i].val+=1; 87 continue; 88 } 89 p[i].val+=0.3; 90 } 91 for(int j=0;j<c;j++){ 92 scanf("%d",&rat[j]); 93 } 94 sort(rat,rat+c); 95 if(c>2){ 96 p[i].val+=max(0.0,(rat[c-3]-1200.0)/100.0)*1.5; 97 } 98 } 99 sort(p,p+n); 100 for(int i=0;i<m;i++){ 101 cout<<p[i].name; 102 printf(" %.3f\n",p[i].val); 103 } 104 } 105 } 106 return 0; 107 }