标签:des style blog http io ar color os sp
Description
Input
Output
Sample Input
2 A: B: 4 A:BC B:ACD C:ABD D:BC 4 A:BCD B:ACD C:ABD D:ABC 0
Sample Output
1 channel needed. 3 channels needed. 4 channels needed.
Source
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 using namespace std; 6 const int ms=26; 7 int n; 8 int b[ms]; 9 int c[ms]; 10 int edge[ms][ms]; 11 void input() 12 { 13 char str[ms+3]; 14 int i,j; 15 memset(edge,0,sizeof(edge)); 16 memset(c,-1,sizeof(c)); 17 for(i=0;i<n;i++) 18 { 19 scanf("%s",str); 20 int len=strlen(str); 21 for(j=2;j<len;j++) 22 { 23 edge[str[0]-‘A‘][str[j]-‘A‘]=1; 24 edge[str[j]-‘A‘][str[0]-‘A‘]=1; 25 } 26 } 27 28 } 29 void solve() 30 { 31 int i,j,ans=0; 32 for(i=0;i<n;i++) 33 { 34 memset(b,0,sizeof(b)); 35 for(j=0;j<n;j++) 36 { 37 if(edge[i][j]&&c[j]!=-1) 38 b[c[j]]=1; 39 } 40 for(j=0;j<=i;j++) 41 if(b[j]==0) 42 break; 43 c[i]=j; 44 } 45 for(i=0;i<n;i++) 46 if(ans<c[i]) 47 ans=c[i]; 48 ans++; 49 if(ans==1) 50 printf("%d channel needed.\n",ans); 51 else 52 printf("%d channels needed.\n",ans); 53 return ; 54 } 55 int main() 56 { 57 while(scanf("%d",&n)==1&&n) 58 { 59 input(); 60 solve(); 61 } 62 return 0; 63 }
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/767355675hutaishi/p/4136013.html