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

            聚精會神搞建設(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) 評論(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 
            久久精品国产欧美日韩99热| 九九久久99综合一区二区| 久久亚洲国产午夜精品理论片| 亚洲精品NV久久久久久久久久| 97久久综合精品久久久综合| 久久精品国产99久久无毒不卡| 色欲综合久久躁天天躁蜜桃| 亚洲中文久久精品无码| 中文字幕久久久久人妻| 欧美亚洲国产精品久久| 色婷婷综合久久久久中文| 久久精品麻豆日日躁夜夜躁| 久久国产精品久久| 久久亚洲精品中文字幕三区| 久久精品国产99久久香蕉| 午夜精品久久影院蜜桃| 久久国产免费直播| 久久91综合国产91久久精品| 青青青青久久精品国产h| 久久久久亚洲AV无码专区桃色| 天天综合久久一二三区| 性欧美丰满熟妇XXXX性久久久 | 久久综合伊人77777| 大香伊人久久精品一区二区| 久久亚洲精品中文字幕| 91久久精品国产成人久久| 亚洲国产精品无码久久久久久曰| 国产aⅴ激情无码久久| 久久九九亚洲精品| 综合久久精品色| 久久免费线看线看| 偷窥少妇久久久久久久久| 久久国产精品无码HDAV| 久久露脸国产精品| 国内精品久久久久久99蜜桃| 久久香蕉国产线看观看猫咪?v| 午夜精品久久久久久久| 久久久国产精品| 久久亚洲欧美国产精品| 久久九九久精品国产免费直播| 曰曰摸天天摸人人看久久久|