Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
why wa?# include <stdio.h> # include <string.h> # include <stdlib.h> # define MAX 30 struct names{ char s[30]; int num; }name[30]; int cmp(const void *a,const void *b) { names a1=*(names *)a; names b1=*(names *)b; return strcmp(a1.s,b1.s); } int vm1[MAX], vm2[MAX]; int Find(bool vc [][MAX],int nv1,int nv2) { int i, j, x, n; int q[MAX], prev[MAX], qs, qe; n = 0; for( i = 0; i < nv1; i++ ) vm1[i] = -1; for( i = 0; i < nv2; i++ ) vm2[i] = -1; for( i = 0; i < nv1; i++ ) { for( j = 0; j < nv2; j++ ) prev[j] = -2; qs = qe = 0; for( j = 0; j < nv2; j++ ) if( vc[i][j] ) { prev[j] = -1; q[qe++] = j; } while( qs < qe ) { x = q[qs]; if( vm2[x] == -1 ) break; qs++; for( j = 0; j < nv2; j++ ) if( prev[j] == -2 && vc[vm2[x]][j] ) { prev[j] = x; q[qe++] = j; } } if( qs == qe ) continue; while( prev[x] > -1 ) { vm1[vm2[prev[x]]] = x; vm2[x] = vm2[prev[x]]; x = prev[x]; } vm2[x] = i; vm1[i] = x; n++; } return n; } int main() { int n,i,j,k,t,block; char ID[30][30],s[30]; int Exist[30],match[30],mat; bool a[30][30]; //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); scanf("%d",&block); while(block--){ scanf("%d",&n); for(i=0;i<n;i++) scanf("%s",ID[i]); for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=1; for(i=0;i<n;i++) Exist[i]=0; k=0; while(1){ scanf("%s",&s); if(strcmp(s,"Q")==0)break; if(strcmp(s,"E")==0){ scanf("%s",s); for(i=0;i<k;i++)if(strcmp(s,name[i].s)==0)break; Exist[i]=1; if(i==k) { name[i].num=i; strcpy(name[k++].s,s); } } if(strcmp(s,"L")==0){ scanf("%s",s); for(i=0;i<k;i++)if(strcmp(s,name[i].s)==0)break; Exist[i]=0; } if(strcmp(s,"M")==0){ scanf("%s",s); for(i=0;i<n;i++)if(strcmp(s,ID[i])==0)break; for(j=0;j<n;j++)if(Exist[j]==0) a[j][i]=0; } } t=Find(a,n,n); for(i=0;i<n;i++) match[i]=vm1[i]; for(i=0;i<n;i++){ a[i][match[i]]=0; if(Find(a,n,n)==n) match[i]=-1; a[i][match[i]]=1; } qsort((void *)name,n,sizeof(name[0]),cmp); for(i=0;i<n;i++){ printf("%s:",name[i].s); mat=match[name[i].num]; if(mat==-1) printf("???\n"); else printf("%s\n",ID[mat]); } if(block) printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator