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 |
Re:四色定理+邻接矩阵+枚举 献丑了In Reply To:四色定理+邻接矩阵+枚举 献丑了 Posted by:jndx20111221395 at 2013-02-02 20:33:52 > #include<cstdio> > #include<cstring> > > bool rela[26][26]; > char str[28] , ans , color[26]; > > char fun( char size ) > { > int i , j , k; > memset( rela , 0 , sizeof( rela ) ); > memset( color , 1 , sizeof( color ) ); > ans = 1; > for( i = 0 ; i < size ; i++ ) > { > scanf("%s" , str ); > for( j = 2 ; str[ j ] >= 'A' ; j++ ) > rela[ i ][ str[ j ] - 'A' ] = 1; > } > for( k = 1 ; k < 4 ; k++ ) > for( i = 0 ; i < size ; i++ ) > if( color[ i ] == k ) > for( j = i+1 ; j < size ; j++ ) > if( rela[ i ][ j ] && color[ j ] == k ) > color[ j ] = k+1; > for( i = 1 , ans = color[0] ; i < size ; i++ ) > if( color[ i ] > ans ) > ans = color[ i ]; > printf("%d channel%sneeded.\n" , ans , ans == 1 ? " " : "s " ); > } > > int main() > { > char size; > while( scanf("%d" , &size ) , size ) > fun( size ); > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator