青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

USACO 2.1.1 The Castle 分析及代碼

The Castle
IOI'94 - Day 1

In a stroke of luck almost beyond imagination, Farmer John was sent a ticket to the Irish Sweepstakes (really a lottery) for his birthday. This ticket turned out to have only the winning number for the lottery! Farmer John won a fabulous castle in the Irish countryside.

Bragging rights being what they are in Wisconsin, Farmer John wished to tell his cows all about the castle. He wanted to know how many rooms it has and how big the largest room was. In fact, he wants to take out a single wall to make an even bigger room.

Your task is to help Farmer John know the exact room count and sizes.

The castle floorplan is divided into M (wide) by N (1 <=M,N<=50) square modules. Each such module can have between zero and four walls. Castles always have walls on their "outer edges" to keep out the wind and rain.

Consider this annotated floorplan of a castle:

     1   2   3   4   5   6   7
  #############################
1 #   |   #   |   #   |   |   #
  #####---#####---#---#####---#
2 #   #   |   #   #   #   #   #
  #---#####---#####---#####---#
3 #   |   |   #   #   #   #   #
  #---#########---#####---#---#
4 # ->#   |   |   |   |   #   #
  #############################
#  = Wall     -,|  = No wall
-> = Points to the wall to remove to
make the largest possible new room

By way of example, this castle sits on a 7 x 4 base. A "room" includes any set of connected "squares" in the floor plan. This floorplan contains five rooms (whose sizes are 9, 7, 3, 1, and 8 in no particular order).

Removing the wall marked by the arrow merges a pair of rooms to make the largest possible room that can be made by removing a single wall.

The castle always has at least two rooms and always has a wall that can be removed.

PROGRAM NAME: castle

INPUT FORMAT

The map is stored in the form of numbers, one number for each module, M numbers on each of N lines to describe the floorplan. The input order corresponds to the numbering in the example diagram above.

Each module number tells how many of the four walls exist and is the sum of up to four integers:

  • 1: wall to the west
  • 2: wall to the north
  • 4: wall to the east
  • 8: wall to the south

Inner walls are defined twice; a wall to the south in module 1,1 is also indicated as a wall to the north in module 2,1.
Line 1: Two space-separated integers: M and N
Line 2..: M x N integers, several per line.

SAMPLE INPUT (file castle.in)

    7 4
    11 6 11 6 3 10 6
    7 9 6 13 5 15 5
    1 10 12 7 13 7 5
    13 11 10 8 10 12 13
    

OUTPUT FORMAT

The output contains several lines:
Line 1: The number of rooms the castle has.
Line 2: The size of the largest room
Line 3: The size of the largest room creatable by removing one wall
Line 4: The single wall to remove to make the largest room possible

Choose the optimal wall to remove from the set of optimal walls by choosing the wall farthest to the west (and then, if still tied, farthest to the south). Name that wall by naming the module that borders it on either the west or south, along with a direction of N or E giving the location of the wall with respect to the module.

SAMPLE OUTPUT (file castle.out)

5
            9
            16
            4 1 E
           

Analysis

Algorithm:

Initially, we need to change the bitnumber into an exact wall map. Later, determine the connection of two rooms nearby. In order to determine the room, just use the traditional Floodfill algorithm. Well,everything cames quite easy.

Code:
            
/*
ID:braytay1
PROG:castle
LANG:C++
*/

#include 
<fstream>

using namespace std;

bool wall[50][50][4];
int n,m,r_num,size[50*50+1],room[50][50];

void dfs(int,int);

int main() {
    ifstream fin (
"castle.in");
    ofstream fout (
"castle.out");
    
int s_max=0,c_max=0,ans_x,ans_y;
    
char ans_w;
    fin 
>> n >> m;
    
for (int i=0;i<m;i++
        
for (int j=0;j<n;j++{
            
int tem;
            fin 
>> tem;
            
for (int k=0;k<=3;k++)  wall[i][j][k]=(tem>>k)&1;
        }

    
//Initialization
    for (int i=0;i<m;i++
        
for (int j=0;j<n;j++
            
if (!room[i][j]) {
                r_num
++;
                size[r_num]
=0;
                dfs(i,j);
                s_max
=max(s_max,size[r_num]);
            }

    
//room mark
    for (int i=0;i<n;i++
        
for (int j=m-1;j>=0;j--{
            
int a=room[j][i],b=room[j][i<n-1?i+1:0],c=room[j>0?j-1:0][i];
            
if (j>0 && wall[j][i][1&& a!=&& size[a]+size[c]>c_max) {
                c_max
=size[a]+size[c];
                ans_x
=j;
                ans_y
=i;
                ans_w
='N';
            }

            
if (i<n-1 && wall[j][i][2&& a!=&& size[a]+size[b]>c_max) {
                c_max
=size[a]+size[b];
                ans_x
=j;
                ans_y
=i;
                ans_w
='E';
            }

        }

    
//break walls
    fout << r_num << endl << s_max << endl << c_max << endl << ans_x+1 << ' ' << ans_y+1 << ' ' << ans_w << endl;
    fin.close();
    fout.close();
    
return 0;
}


void dfs(int x,int y) {
    
if (room[x][y]==r_num) return;
    room[x][y]
=r_num;
    size[r_num]
++;
    
if (!wall[x][y][0]) dfs(x,y-1);
    
if (!wall[x][y][1]) dfs(x-1,y);
    
if (!wall[x][y][2]) dfs(x,y+1);
    
if (!wall[x][y][3]) dfs(x+1,y);
}

posted on 2008-08-07 14:37 幻浪天空領主 閱讀(429) 評論(0)  編輯 收藏 引用 所屬分類: USACO

<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

導航

統計

常用鏈接

留言簿(1)

隨筆檔案(2)

文章分類(23)

文章檔案(22)

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            精东粉嫩av免费一区二区三区| 国精品一区二区| 一区二区三区国产精华| 亚洲欧洲另类国产综合| 欧美福利一区二区| 亚洲精品孕妇| 一区二区三区精密机械公司| 国产精品久久久久久久久婷婷 | 欧美成va人片在线观看| 亚洲国产精品一区在线观看不卡| 欧美成人国产| 欧美日韩午夜| 久久久国产视频91| 久久综合久久综合九色| 99热这里只有成人精品国产| 亚洲午夜视频在线观看| 国内精品模特av私拍在线观看| 欧美fxxxxxx另类| 欧美午夜精品久久久久久浪潮 | 亚洲欧洲美洲综合色网| 日韩网站免费观看| 国产婷婷色一区二区三区在线 | 久久在线免费观看视频| 免费不卡在线观看av| 亚洲一区二区3| 久久天堂国产精品| 亚洲午夜视频在线观看| 久久精品中文字幕一区| 亚洲少妇自拍| 久久久久久穴| 小黄鸭精品aⅴ导航网站入口 | 中文国产亚洲喷潮| 一区二区视频在线观看| 日韩午夜在线电影| 在线免费日韩片| 亚洲一区免费| 一区二区日韩欧美| 毛片一区二区三区| 欧美资源在线观看| 欧美性猛交xxxx乱大交蜜桃| 老司机成人在线视频| 国产精品久久久久国产精品日日| 欧美激情1区2区| 国产专区精品视频| 一区二区三区精密机械公司 | 国产综合色产| 亚洲性感美女99在线| 亚洲美女在线看| 鲁鲁狠狠狠7777一区二区| 香蕉久久久久久久av网站| 欧美另类变人与禽xxxxx| 老司机精品久久| 国产一区二区三区在线观看精品| 日韩视频三区| 中文一区在线| 欧美精品一区二区精品网 | 午夜在线视频观看日韩17c| 你懂的视频欧美| 免费短视频成人日韩| 国语自产精品视频在线看8查询8| 99这里有精品| 亚洲一区中文| 欧美亚州在线观看| 99热精品在线| 午夜精品久久久久久久久久久| 欧美日韩免费高清一区色橹橹| 亚洲狠狠丁香婷婷综合久久久| 亚洲激情图片小说视频| 麻豆成人av| 亚洲第一精品夜夜躁人人爽| 91久久夜色精品国产九色| 免费观看成人www动漫视频| 欧美高清在线观看| 亚洲日本一区二区| 欧美日韩国产区一| 在线视频欧美日韩精品| 欧美一级夜夜爽| 极品尤物av久久免费看| 噜噜噜久久亚洲精品国产品小说| 亚洲国产成人porn| 亚洲视频一区在线| 国产精品腿扒开做爽爽爽挤奶网站| 亚洲午夜女主播在线直播| 久久成人羞羞网站| 国产日本欧美一区二区三区| 久久国内精品自在自线400部| 欧美va日韩va| 亚洲一区视频在线| 国产一区二区0| 欧美成人首页| 亚洲一区区二区| 欧美国产日本| 亚洲尤物在线视频观看| 狠色狠色综合久久| 欧美日韩国产bt| 欧美在线3区| 亚洲激情在线观看| 久久国产精品一区二区三区四区| 亚洲第一色在线| 欧美日韩综合视频| 久久精品中文字幕一区| 亚洲免费观看高清完整版在线观看熊| 亚洲欧美制服中文字幕| 亚洲国产日韩欧美| 国产精品美腿一区在线看| 久久免费一区| 亚洲一区二区视频在线观看| 欧美成人国产va精品日本一级| 亚洲欧美成人综合| 亚洲狠狠丁香婷婷综合久久久| 国产精品日韩欧美大师| 蜜桃av一区二区三区| 亚洲男人的天堂在线aⅴ视频| 欧美国产国产综合| 久久精品91久久久久久再现| 一区二区91| 亚洲福利久久| 国产一区日韩欧美| 国产精品久久网站| 欧美交受高潮1| 久久九九免费| 欧美亚洲免费在线| 一区二区欧美视频| 亚洲人成网站在线观看播放| 久久综合狠狠综合久久激情| 午夜精品久久久久久久男人的天堂| 亚洲肉体裸体xxxx137| 永久免费视频成人| 国产专区一区| 国产亚洲精品美女| 国产视频一区在线观看| 欧美午夜视频一区二区| 欧美精品一区三区在线观看| 老牛嫩草一区二区三区日本| 久久高清一区| 久久精品一区二区三区不卡| 欧美一区二区三区免费大片| 午夜国产精品影院在线观看| 在线亚洲一区观看| 正在播放亚洲| 一区二区三区久久网| 一区二区三区四区国产| 一本色道久久综合一区| 日韩午夜电影在线观看| 99pao成人国产永久免费视频| 亚洲国产日韩精品| 亚洲茄子视频| 日韩视频一区二区| 99精品免费| 亚洲综合视频一区| 欧美一区2区视频在线观看| 欧美亚洲午夜视频在线观看| 性伦欧美刺激片在线观看| 欧美一区二区三区免费观看| 久久精品一本| 男人插女人欧美| 欧美日韩国产一区二区三区| 国产精品不卡在线| 国产精品久久久久久久久久免费| 国产精品视频yy9299一区| 国产亚洲一区二区精品| 精品成人a区在线观看| 亚洲日本中文| 亚洲免费伊人电影在线观看av| 亚洲综合色在线| 久久综合激情| 亚洲欧洲一区二区天堂久久 | 欧美在线视频二区| 久久久久久9999| 欧美大片一区二区| 国产精品热久久久久夜色精品三区| 国产九色精品成人porny| 狠狠狠色丁香婷婷综合久久五月| 亚洲人成高清| 欧美一区二区视频网站| 欧美h视频在线| 亚洲调教视频在线观看| 久久久久久成人| 欧美日韩一级视频| 在线精品国产欧美| 亚洲一区二区视频在线| 久久一区二区三区国产精品| 日韩视频在线播放| 久久精品人人爽| 欧美日韩中文精品| 影音先锋欧美精品| 亚洲欧美日韩国产精品| 美女网站在线免费欧美精品| 一区二区日韩伦理片| 快射av在线播放一区| 国产美女一区二区| 日韩亚洲欧美综合| 老妇喷水一区二区三区| 一区二区三区高清在线| 欧美www视频在线观看| 国产亚洲女人久久久久毛片| 亚洲午夜影视影院在线观看| 欧美国产成人精品| 欧美在线免费视屏| 国产精品久久看|