标签:des style blog color io os java ar strong
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 2593 Accepted Submission(s): 742
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <iostream> 5 #include <algorithm> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 using namespace std; 10 11 int di[2005][2005]; 12 map<string,int>ma; 13 map<int,string>mb; 14 vector<int>ve[2005]; 15 int visited[2005]; 16 int n, Q; 17 18 bool cmp(char s1[],char s2[]){ 19 return strcmp(s1,s2)>0; 20 } 21 22 main() 23 { 24 int i, j, k; 25 int t, kase=1; 26 cin>>t; 27 char c1[20], c2[20]; 28 while(t--){ 29 ma.clear();mb.clear(); 30 for(i=0;i<n*2+5;i++) ve[i].clear(); 31 32 scanf("%d %d",&n,&Q); 33 k=0; 34 int x, y; 35 memset(di,0,sizeof(di)); 36 for(i=0;i<n;i++){ 37 scanf("%s%s",c1,c2); 38 if(ma.find(c1)!=ma.end()) x=ma[c1]; 39 else 40 ma[c1]=k++,x=ma[c1],mb[x]=c1; 41 if(ma.find(c2)!=ma.end()) y=ma[c2]; 42 else 43 ma[c2]=k++,y=ma[c2],mb[y]=c2; 44 ve[x].push_back(y); 45 ve[y].push_back(x); 46 di[x][y]=di[y][x]=1; 47 } 48 int f; 49 int num[2005]; 50 int id=0; 51 string ss[2005]; 52 int maxh, z; 53 printf("Case %d:\n",kase++); 54 while(Q--){ 55 scanf("%s",c1); 56 id=0; 57 memset(num,0,sizeof(num)); 58 x=ma[c1]; 59 f=0; 60 maxh=-1; 61 for(i=0;i<ve[x].size();i++){ 62 y=ve[x][i]; 63 for(j=0;j<ve[y].size();j++){ 64 z=ve[y][j]; 65 if(z!=x&&!di[z][x]){ 66 num[z]++;f=1; 67 maxh=max(maxh,num[z]); 68 } 69 } 70 } 71 if(!f) { 72 printf("-\n");continue; 73 } 74 for(i=0;i<k;i++) { 75 if(num[i]==maxh){ 76 ss[id++]=mb[i]; 77 } 78 } 79 std::sort(ss,ss+id); 80 cout<<ss[0]; 81 for(i=1;i<id;i++) cout<<" "<<ss[i]; 82 cout<<endl; 83 } 84 } 85 }
标签:des style blog color io os java ar strong
原文地址:http://www.cnblogs.com/qq1012662902/p/3978342.html