• <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>

            superman

            聚精會(huì)神搞建設(shè) 一心一意謀發(fā)展
            posts - 190, comments - 17, trackbacks - 0, articles - 0
               :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Section 2.1 - The Castle

            Posted on 2009-03-25 11:22 superman 閱讀(119) 評(píng)論(0)  編輯 收藏 引用 所屬分類: USACO
              1 #include <iostream>
              2 
              3 using namespace std;
              4 
              5 int n, m;
              6 int castleStructure[50][50];
              7 int castleRegion[50][50];
              8 
              9 int regionCnt;
             10 int areaOfRegions[2500];
             11 
             12 void getRegion(int i, int j)
             13 {
             14     if (castleRegion[i][j] != -1)
             15         return;
             16     castleRegion[i][j] = regionCnt;
             17     if ((castleStructure[i][j] & 1== 0)   //W
             18         getRegion(i, j - 1);
             19     if ((castleStructure[i][j] & 2== 0)   //N
             20         getRegion(i - 1, j);
             21     if ((castleStructure[i][j] & 4== 0)   //E
             22         getRegion(i, j + 1);
             23     if ((castleStructure[i][j] & 8== 0)   //S
             24         getRegion(i + 1, j);
             25 }
             26 
             27 int main()
             28 {
             29     freopen("castle.in""r", stdin);
             30     freopen("castle.out""w", stdout);
             31 
             32     cin >> m >> n;
             33     for (int i = 0; i < n; i++)
             34     for (int j = 0; j < m; j++)
             35         cin >> castleStructure[i][j];
             36 
             37     memset(castleRegion, 255sizeof(castleRegion));
             38 
             39     for (int i = 0; i < n; i++)
             40     for (int j = 0; j < m; j++)
             41         if (castleRegion[i][j] == -1)
             42         {
             43             getRegion(i, j);
             44             regionCnt++;
             45         }
             46 
             47     //ans 1
             48     cout << regionCnt << endl;
             49 
             50     for (int i = 0; i < n; i++)
             51     for (int j = 0; j < m; j++)
             52         areaOfRegions[castleRegion[i][j]]++;
             53 
             54     int maxAreaOfRegions = 0;
             55     for (int i = 0; i < regionCnt; i++)
             56         maxAreaOfRegions >?= areaOfRegions[i];
             57 
             58     //ans 2
             59     cout << maxAreaOfRegions << endl;
             60 
             61     int maxAreaAfterRemoveOneWall = 0;
             62     struct { int x, y, dir; } theWallToRemove;
             63 
             64     for (int j = 0; j < m; j++)
             65         for (int i = n - 1; i >= 0; i--)
             66         {
             67             if ((castleStructure[i][j] & 1== 1 && j - 1 >= 0)   //W
             68             {
             69                 if (castleRegion[i][j] == castleRegion[i][j - 1])
             70                     continue;
             71                 int t = areaOfRegions[castleRegion[i][j]] + areaOfRegions[castleRegion[i][j - 1]];
             72                 if (t > maxAreaAfterRemoveOneWall)
             73                 {
             74                     maxAreaAfterRemoveOneWall = t;
             75                     theWallToRemove.x = i;
             76                     theWallToRemove.y = j;
             77                     theWallToRemove.dir = 1;
             78                 }
             79             }
             80             if ((castleStructure[i][j] & 2== 2 && i - 1 >= 0)   //N
             81             {
             82                 if (castleRegion[i][j] == castleRegion[i - 1][j])
             83                     continue;
             84                 int t = areaOfRegions[castleRegion[i][j]] + areaOfRegions[castleRegion[i - 1][j]];
             85                 if (t > maxAreaAfterRemoveOneWall)
             86                 {
             87                     maxAreaAfterRemoveOneWall = t;
             88                     theWallToRemove.x = i;
             89                     theWallToRemove.y = j;
             90                     theWallToRemove.dir = 2;
             91                 }
             92             }
             93             if ((castleStructure[i][j] & 4== 4 && j + 1 < m)   //E
             94             {
             95                 if (castleRegion[i][j] == castleRegion[i][j + 1])
             96                     continue;
             97                 int t = areaOfRegions[castleRegion[i][j]] + areaOfRegions[castleRegion[i][j + 1]];
             98                 if (t > maxAreaAfterRemoveOneWall)
             99                 {
            100                     maxAreaAfterRemoveOneWall = t;
            101                     theWallToRemove.x = i;
            102                     theWallToRemove.y = j;
            103                     theWallToRemove.dir = 4;
            104                 }
            105             }
            106             if ((castleStructure[i][j] & 8== 8 && i + 1 < n)   //S
            107             {
            108                 if (castleRegion[i][j] == castleRegion[i + 1][j])
            109                     continue;
            110                 int t = areaOfRegions[castleRegion[i][j]] + areaOfRegions[castleRegion[i + 1][j]];
            111                 if (t > maxAreaAfterRemoveOneWall)
            112                 {
            113                     maxAreaAfterRemoveOneWall = t;
            114                     theWallToRemove.x = i;
            115                     theWallToRemove.y = j;
            116                     theWallToRemove.dir = 8;
            117                 }
            118             }
            119         }
            120 
            121     //ans 3
            122     cout << maxAreaAfterRemoveOneWall << endl;
            123     cout << theWallToRemove.x + 1 << ' '
            124          << theWallToRemove.y + 1 << ' ';
            125     if (theWallToRemove.dir == 1) cout << 'W' << endl;
            126     if (theWallToRemove.dir == 2) cout << 'N' << endl;
            127     if (theWallToRemove.dir == 4) cout << 'E' << endl;
            128     if (theWallToRemove.dir == 8) cout << 'S' << endl;
            129 
            130     return 0;
            131 }
            132 
            久久天天婷婷五月俺也去| 四虎亚洲国产成人久久精品| 青春久久| 亚洲欧美伊人久久综合一区二区 | 久久成人国产精品免费软件| 久久久无码精品亚洲日韩京东传媒| 亚洲乱码精品久久久久..| 97久久精品无码一区二区天美 | 色婷婷久久综合中文久久蜜桃av| 久久夜色精品国产噜噜亚洲AV| 欧美一区二区精品久久| 久久久久久国产精品无码下载| 婷婷伊人久久大香线蕉AV | 精品久久人妻av中文字幕| 久久国产影院| 国产午夜精品理论片久久影视| 亚洲欧美另类日本久久国产真实乱对白| 一本一本久久A久久综合精品| 久久超乳爆乳中文字幕| 无码任你躁久久久久久老妇| 久久综合久久久| 国产精品对白刺激久久久| 精品久久久久成人码免费动漫 | 欧美亚洲另类久久综合婷婷 | 久久91精品国产91| 九九久久精品无码专区| 欧美精品一区二区精品久久| 久久精品国产亚洲AV电影| 99蜜桃臀久久久欧美精品网站| 日日狠狠久久偷偷色综合96蜜桃| 久久久久久免费一区二区三区| 亚洲欧美日韩久久精品第一区| 久久国语露脸国产精品电影| 久久久久亚洲精品中文字幕| 欧美一区二区精品久久| 久久精品国产免费一区| 久久精品国产精品亚洲精品| 久久国产精品久久久| 四虎国产精品免费久久5151| 久久国产一区二区| 婷婷久久综合九色综合98|