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 |
大概就这个样子,用了一次Floyd.In Reply To:这个题, 我郁闷了N天 Posted by:xfxyjwf at 2005-07-11 22:03:32 #include <stdio.h> #include <string.h> #define MAXA 100 #define MAXB 100 int cap[MAXA+1][MAXB+1]; int recept[MAXA+1],plug[MAXB+1],na,nb; char str[4*MAXA+1][50]; int str_n; int connect[4*MAXA+1][4*MAXA+1]; int Insert(const char ss[50]) { int i; for(i=1;i<=str_n;i++) if(strcmp(str[i],ss) == 0) break; if(i <= str_n) return i; strcpy(str[++str_n],ss); return str_n; } int main() { int i,j,k; char ss[50],st[50]; scanf("%d",&na); for(i=1;i<=na;i++) { scanf("%s",ss); recept[i] = Insert(ss); } scanf("%d",&nb); for(i=1;i<=nb;i++) { scanf("%s %s",st,ss); plug[i] = Insert(ss); } scanf("%d",&k); for(i=1;i<=k;i++) { scanf("%s %s",st,ss); connect[Insert(ss)][Insert(st)] = 1; } for(i=1;i<=str_n;i++) connect[i][i] = 1; for(k=1;k<=str_n;k++) { for(i=1;i<=str_n;i++) { if(!connect[i][k]) continue; for(j=1;j<=str_n;j++) { if(connect[k][j]) connect[i][j] = 1; } } } for(i=1;i<=na;i++) { for(j=1;j<=nb;j++) { if(connect[recept[i]][plug[j]]) cap[i][j] = 1; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator