uva 10615

2014-11-24 12:36:38 · 作者: · 浏览: 0

题意:给出一个方格图,里面有一些是“*”,你要为他们染色,使得每行每列不会有同样的颜色,并且颜色要最少。




思路:这题给跪了。。。建图的话是按行号和列号分别为两个集合,如果该行该列有“*”,就连一条线,我就只能想到这里了。。。。然后颜色的最少数目为这个图里面最大的度数。。。不会证明,不要问我。然后做法就是为这个二分图补充一些边使得每个点的度数等于最大度数。然后开始匹配,匹配一次,就把边给删掉。如果匹配出的行列有”*“,就标颜色到输出答案中,否则不用管。

疑问:为什么一定要不图补成完全二分图? 如果不补 , 那么就会wa

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         using namespace std; const int maxn = 105; int n , rook; int board[maxn][maxn]; char buffer[maxn][maxn]; int link[maxn]; bool T[maxn]; vector
        
          G[maxn]; int deg[maxn]; void input() { memset(buffer,0,sizeof(buffer)); scanf(%d,&n); rook = 0; memset(deg,0,sizeof(deg)); for (int i = 0 ; i < n ; ++i) { G[i].clear(); scanf(%s,buffer[i]); int cnt = 0; for (int j = 0 ; j < n ; ++j) { if (buffer[i][j]=='*') { ++cnt; G[i].push_back(j); ++deg[j]; } } rook = max(rook,cnt); } for (int i = 0 ; i < n ; ++i) { int cnt = 0; for (int j = n-1 ; j >= 0 ; --j) if (buffer[j][i]=='*') ++cnt; rook = max(rook,cnt); } for (int i = 0 ; i < n ; ++i)//配成一个完全图 if (G[i].size()
         
          >T; while (T--) { input(); solve(); } } /* *... .*.. ..*. ...* */