• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Why so serious? --[NKU]schindlerlee

            2010年02月07日星期日.sgu190 二分圖

            2010年02月07日星期日.sgu190
            sgu190:
            一開始想到的竟然是狀態壓縮dp,然后一看n,貌似大了點。
            然后怎么想也沒思路,上網看看,才知道原來二分圖還可以這么用,我怎么從來也沒想到呢。。。。

            將圖像國際象棋棋盤那樣黑白染色,然后給對于每個顏色給每個格子一個編號。
            然后選一個染色,對每個格子和他旁邊的格子建邊,這樣構成一個二分圖。
            求出最大的匹配數,然后再按照題目的猥瑣要求輸出即可。

            注意 題目中棋盤的格式是這個樣子的。
            (2,1) (2,2)
            (1,1) (1,2)
            左下角是(1,1)
            如果按照平常的左上角是(1,1)來搞,需要注意一下輸出

              1 
              2 int g[801][801],n,P;
              3 const int BLACK = 1;
              4 const int WHITE = 2;
              5 const int REMOVED = 3;
              6 int num[41][41],bsp,wsp,cnt;
              7 int board[41][41];
              8 int bcoord[41*41][2];
              9 int wcoord[41*41][2];
             10 int vis[801];
             11 int L[801],R[801];
             12 
             13 bool make_graph()
             14 {
             15   int i,j;cnt = 0;
             16   for (i = 1;i <= n;i++) {
             17       for (j = 1;j <= n;j++) {
             18           if (board[i][j] != REMOVED) {
             19               cnt ++;
             20               if ((i+j)%2==1) {
             21                   board[i][j] = WHITE;
             22                   wcoord[wsp][0= i, wcoord[wsp][1= j;
             23                   num[i][j] = wsp++;
             24               }else {
             25                   board[i][j] = BLACK;
             26                   bcoord[bsp][0= i, bcoord[bsp][1= j;
             27                   num[i][j] = bsp++;
             28               }
             29           }
             30       }
             31   }
             32   for (i = 1;i <= n;i++) {
             33       for (j = 1;j <= n;j++) {
             34           if (board[i][j] == BLACK) {
             35               if (board[i+1][j] == WHITE) g[num[i][j]][num[i+1][j]] = 1;
             36               if (board[i][j+1== WHITE) g[num[i][j]][num[i][j+1]] = 1;
             37               if (board[i-1][j] == WHITE) g[num[i][j]][num[i-1][j]] = 1;
             38               if (board[i][j-1== WHITE) g[num[i][j]][num[i][j-1]] = 1;
             39           }
             40       }
             41   }
             42   return true;
             43 }
             44 
             45 bool dfs(int u) {
             46   for (int v = 0;v < wsp;v++) {
             47       if (g[u][v] && !vis[v]) {
             48           vis[v] = true;
             49           if (R[v] == -1 || dfs(R[v])) {
             50               L[u] = v;
             51               R[v] = u;
             52               return true;
             53           }
             54       }
             55   }
             56   return false;
             57 }
             58 
             59 int MaxMatch()
             60 {
             61   int i,res = 0;
             62   memset(L,-1,sizeof(L));
             63   memset(R,-1,sizeof(R));
             64 
             65   for (i = 0;i < bsp;i++) {
             66       if (L[i] == -1) {
             67           memset(vis,0,sizeof(vis));
             68           if (dfs(i)) {
             69               res++;
             70           }
             71       }
             72   }
             73   return res;
             74 }
             75 
             76 int out[801][2],top;
             77 bool proc()
             78 {
             79   make_graph(); if (cnt & 1) { return false; }
             80   if (bsp == 0 || wsp == 0) { return false; }
             81   if (bsp != wsp) { return false; }
             82   return (MaxMatch() * 2 == cnt);
             83 }
             84 
             85 int main()
             86 {
             87   int i,j,k,a,b;
             88   scanf("%d%d",&n,&P);
             89   for (i = 0;i < P;i++) {
             90       scanf("%d%d",&a,&b);
             91       board[a][b] = REMOVED;
             92   }
             93   if (proc()) {
             94       printf("Yes\n");
             95       top = 0;
             96       for (i = 0;i < bsp;i++) {
             97           if (bcoord[i][1== wcoord[L[i]][1]) {
             98               if (bcoord[i][0< wcoord[L[i]][0]) {
             99                   out[top][0= bcoord[i][0];
            100                   out[top][1= bcoord[i][1];
            101                   top++;
            102               }else {
            103                   out[top][0= wcoord[L[i]][0];
            104                   out[top][1= wcoord[L[i]][1];
            105                   top++;
            106               }
            107           }
            108       }
            109 
            110       printf("%d\n",top);
            111       for (i = 0;i < top;i++) { printf("%d %d\n",out[i][0],out[i][1]); }
            112 
            113       top = 0;
            114       for (i = 0;i < bsp;i++) {
            115           if (bcoord[i][0== wcoord[L[i]][0]) {
            116               if (bcoord[i][1< wcoord[L[i]][1]) {
            117                   out[top][0= bcoord[i][0];
            118                   out[top][1= bcoord[i][1];
            119                   top++;
            120               }else {
            121                   out[top][0= wcoord[L[i]][0];
            122                   out[top][1= wcoord[L[i]][1];
            123                   top++;
            124               }
            125           }
            126       }//http://m.shnenglu.com/schindlerlee
            127       printf("%d\n",top);
            128       for (i = 0;i < top;i++) { printf("%d %d\n",out[i][0],out[i][1]); }
            129   }else {
            130       printf("No\n");
            131   }
            132 
            133 
            134   return 0;
            135 }
            136 
            137 

            posted on 2010-02-07 15:06 schindlerlee 閱讀(1040) 評論(0)  編輯 收藏 引用 所屬分類: 解題報告

            伊人久久大香线蕉精品不卡| 99久久国产综合精品女同图片| 国产情侣久久久久aⅴ免费| 久久不见久久见免费视频7| 国产激情久久久久影院老熟女| 亚洲精品无码久久久| 国产精品久久久久影院色| 欧美麻豆久久久久久中文| avtt天堂网久久精品| 亚洲欧洲精品成人久久曰影片 | 久久亚洲精品无码aⅴ大香 | 性高朝久久久久久久久久| 无码国内精品久久人妻蜜桃| 狠狠色综合网站久久久久久久| 伊人久久精品无码二区麻豆| 国产精品熟女福利久久AV| 一本色道久久HEZYO无码| 久久九色综合九色99伊人| 国产一久久香蕉国产线看观看 | 久久国产成人午夜aⅴ影院| 久久永久免费人妻精品下载| 欧美日韩精品久久久久| 精品亚洲综合久久中文字幕| 久久久亚洲欧洲日产国码aⅴ| 久久中文字幕精品| 亚洲国产成人久久精品99| 久久久久久无码国产精品中文字幕 | 久久精品成人免费观看97| 99久久国产热无码精品免费| 久久偷看各类wc女厕嘘嘘| 精品国产青草久久久久福利| 国产精品乱码久久久久久软件 | 性做久久久久久久久久久| 久久精品中文字幕有码| 国产亚洲精午夜久久久久久| 国产亚州精品女人久久久久久| 九九久久精品国产| 久久精品这里只有精99品| 色悠久久久久久久综合网| 亚洲精品国产第一综合99久久| 偷偷做久久久久网站|