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

USACO Section 2.4 Overfencing

Overfencing

Kolstad and Schrijvers

Farmer John went crazy and created a huge maze of fences out in a field. Happily, he left out two fence segments on the edges, and thus created two "exits" for the maze. Even more happily, the maze he created by this overfencing experience is a `perfect' maze: you can find a way out of the maze from any point inside it.

Given W (1 <= W <= 38), the width of the maze; H (1 <= H <= 100), the height of the maze; 2*H+1 lines with width 2*W+1 characters that represent the maze in a format like that shown later - then calculate the number of steps required to exit the maze from the `worst' point in the maze (the point that is `farther' from either exit even when walking optimally to the closest exit). Of course, cows walk only parallel or perpendicular to the x-y axes; they do not walk on a diagonal. Each move to a new square counts as a single unit of distance (including the move "out" of the maze.

Here's what one particular W=5, H=3 maze looks like:

+-+-+-+-+-+
|         |
+-+ +-+ + +
|     | | |
+ +-+-+ + +
| |     |
+-+ +-+-+-+

Fenceposts appear only in odd numbered rows and and odd numbered columns (as in the example). The format should be obvious and self explanatory. Each maze has exactly two blank walls on the outside for exiting.

PROGRAM NAME: maze1

INPUT FORMAT

Line 1: W and H, space separated
Lines 2 through 2*H+2: 2*W+1 characters that represent the maze

SAMPLE INPUT (file maze1.in)

5 3
    +-+-+-+-+-+
    |         |
    +-+ +-+ + +
    |     | | |
    + +-+-+ + +
    | |     |
    +-+ +-+-+-+
    

OUTPUT FORMAT

A single integer on a single output line. The integer specifies the minimal number of steps that guarantee a cow can exit the maze from any possible point inside the maze.

SAMPLE OUTPUT (file maze1.out)

9
    
The lower left-hand corner is *nine* steps from the closest exit.

Analysis

We can solve this with a standard flood fill, using a queue to implement breadth first search. It is convenient to leave the maze in its ASCII format and just look at it as a bunch of characters, with non-space characters being walls.


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

#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<assert.h>
#include 
<algorithm>
#include 
<queue>
using namespace std;
queue
<int> qq;
int W,H;
char map[202][80];
int tracy[202][80][2];
int x1=-1,y1=-1,x2=-1,y2=-1;
bool isIn(int x,int y){
    
if (x<=0||x>=2*H||y<=0||y>=2*W) return false;
    
else return true;
}

void BFS(int tra){
    
int col,row,s;
    
while (!qq.empty()){
        col
=qq.front();
        qq.pop();
        row
=qq.front();
        qq.pop();
        s
=qq.front();
        qq.pop();
        
if (tracy[col][row][tra]>0continue;
        tracy[col][row][tra]
=s;
        
if (map[col-1][row]!='-'&&isIn(col-2,row)) {qq.push(col-2);qq.push(row);qq.push(s+1);}
        
if (map[col+1][row]!='-'&&isIn(col+2,row)) {qq.push(col+2);qq.push(row);qq.push(s+1);}
        
if (map[col][row-1]!='|'&&isIn(col,row-2)) {qq.push(col);qq.push(row-2);qq.push(s+1);}
        
if (map[col][row+1]!='|'&&isIn(col,row+2)) {qq.push(col);qq.push(row+2);qq.push(s+1);}
    }

}

int max(int a[202][80][2],int tra,int h,int w){
    
int maximum=-1;
    
for (int i=0;i<h;i++){
        
for (int j=0;j<w;j++){
            
if (maximum<a[i][j][tra]) maximum=a[i][j][tra];
        }

    }

    
return maximum;
}


int main(){
    
//Initialize
    FILE *fin, *fout;
    fin 
= fopen("maze1.in""r");
    fout 
= fopen("maze1.out""w");
    assert(fin 
!= NULL && fout != NULL);
    fscanf(fin,
"%d %d\n",&W,&H);
    
for (int i=0;i<=2*H;i++){
        fgets(map[i], 
sizeof(map[i]), fin);
    }

    memset(tracy,
-1,sizeof(tracy));
    
//edge search
    for (int i=0;i<=2*W;i++){
        
if (map[0][i]!='+'&&map[0][i]!='-'{
            
if (x1==-1&&y1==-1{x1=1;y1=i;}
            
else {x2=1;y2=i;}
        }

        
if (map[2*H][i]!='+'&&map[2*H][i]!='-'{
            
if (x1==-1&&y1==-1{x1=2*H-1;y1=i;}
            
else {x2=2*H-1;y2=i;}
        }

    }

    
for (int i=0;i<=2*H;i++){
        
if (map[i][0]!='+'&&map[i][0]!='|'{
            
if (x1==-1&&y1==-1{x1=i;y1=1;}
            
else {x2=i;y2=1;}
        }

        
if (map[i][2*W]!='+'&&map[i][2*W]!='|'{
            
if (x1==-1&&y1==-1{x1=i;y1=2*W-1;}
            
else {x2=i;y2=2*W-1;}
        }

    }

    qq.push(x1);qq.push(y1);qq.push(
1);
    BFS(
0);
    qq.push(x2);qq.push(y2);qq.push(
1);
    BFS(
1);
    
for (int i=0;i<=2*H;i++){
        
for (int j=0;j<=2*W;j++){
            
int a1,a2;
            a1
=tracy[i][j][0];
            a2
=tracy[i][j][1];
            tracy[i][j][
0]=(a1<a2)?a1:a2;
        }

    }

    
int res;
    res
=max(tracy,0,2*H+1,2*W+1);
    
//Output
    fprintf(fout, "%d\n", res);
    
return 0;
}

posted on 2008-08-15 16:55 幻浪天空領主 閱讀(165) 評論(0)  編輯 收藏 引用 所屬分類: USACO

<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

導航

統計

常用鏈接

留言簿(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>
            午夜精品久久久| 欧美日韩成人精品| 亚洲韩日在线| 欧美va亚洲va香蕉在线| 美女网站久久| 欧美激情91| 亚洲精品乱码久久久久| 夜夜狂射影院欧美极品| 亚洲欧美激情一区二区| 久久国产日本精品| 久久综合一区二区| 欧美吻胸吃奶大尺度电影| 国产精品乱人伦一区二区| 国内精品一区二区三区| 亚洲欧洲精品一区二区三区不卡| 日韩视频在线你懂得| 亚洲一区二区三区在线看| 久久丁香综合五月国产三级网站| 免费亚洲一区| 亚洲一区在线直播| 久久人人爽人人爽| 欧美色综合网| 精东粉嫩av免费一区二区三区| 日韩视频一区二区在线观看 | 亚洲精品一区在线观看| 国产精品99久久久久久久女警 | 亚洲精品美女久久久久| 午夜宅男久久久| 欧美大片在线观看一区| 在线一区亚洲| 欧美黑人一区二区三区| 国产午夜精品全部视频在线播放| 亚洲精品乱码久久久久久按摩观| 性欧美超级视频| 亚洲精品国久久99热| 久久国产99| 国产伦精品一区二区三区四区免费| 亚洲国产精品久久久久| 久久国产日韩| 一区二区三区日韩欧美| 欧美成人小视频| 在线观看一区二区视频| 久久激情婷婷| 亚洲欧美视频在线| 国产精品久久国产愉拍| 一本一本大道香蕉久在线精品| 久久中文在线| 亚洲欧美日韩国产| 欧美三级视频在线播放| 亚洲免费不卡| 亚洲国产高清一区二区三区| 欧美一区二区黄色| 国产精品捆绑调教| 亚洲自拍偷拍色片视频| 一区二区冒白浆视频| 欧美激情影音先锋| 99国产精品久久| 亚洲精品一区二区三区四区高清| 久久一区二区三区四区| 在线播放日韩| 欧美黑人一区二区三区| 开心色5月久久精品| 在线观看亚洲专区| 欧美激情一区二区三区全黄 | 亚洲一区激情| 国产精品久久网| 欧美一区二区精品| 亚洲一区在线免费观看| 国产婷婷色一区二区三区在线 | 亚洲第一主播视频| 欧美77777| 欧美精品一区三区| 国产精品久久久久久亚洲毛片 | 亚洲欧美日韩国产另类专区| 中文在线一区| 国产亚洲成年网址在线观看| 久久久福利视频| 老**午夜毛片一区二区三区| 亚洲精品欧美极品| 一区二区91| 国精品一区二区三区| 欧美成人有码| 国产精品videosex极品| 久久日韩粉嫩一区二区三区| 蜜臀99久久精品久久久久久软件| 99re热精品| 午夜在线精品| aa级大片欧美| 久久精品视频在线观看| 亚洲乱码一区二区| 亚洲欧美国产高清| 亚洲另类在线一区| 欧美制服丝袜第一页| 日韩一级在线观看| 欧美一区二区高清在线观看| 亚洲毛片在线| 久久激五月天综合精品| 亚洲视频高清| 欧美**人妖| 久久久久久亚洲精品杨幂换脸| 欧美风情在线观看| 欧美一区二区三区久久精品茉莉花| 久久亚洲影院| 午夜精品亚洲一区二区三区嫩草| 久久久久国产一区二区三区四区| 一本到高清视频免费精品| 久久精品导航| 欧美影院在线| 欧美日韩在线播| 亚洲第一成人在线| 一区二区三区中文在线观看 | 亚洲主播在线| 亚洲午夜91| 麻豆91精品91久久久的内涵| 午夜精品区一区二区三| 欧美日韩国产精品一卡| 欧美成人免费网站| 激情小说另类小说亚洲欧美| 亚洲欧美日产图| 亚洲欧美在线另类| 欧美色精品天天在线观看视频| 亚洲高清精品中出| 一区三区视频| 久久九九电影| 久久久久久电影| 国产婷婷一区二区| 午夜亚洲视频| 久久久美女艺术照精彩视频福利播放| 国产精品theporn| 亚洲深夜福利网站| 亚洲欧美日韩综合国产aⅴ| 欧美日韩国产综合视频在线观看中文 | 亚洲欧美久久| 欧美日韩色婷婷| 亚洲乱码国产乱码精品精可以看| 亚洲电影在线观看| 久久午夜激情| 亚洲成人在线网站| 亚洲国内精品在线| 欧美激情精品久久久| 亚洲电影免费观看高清完整版| 亚洲国产视频a| 欧美成人午夜| 夜夜爽夜夜爽精品视频| 亚洲男人的天堂在线| 国产精品裸体一区二区三区| 亚洲欧美精品一区| 久久视频一区| 亚洲三级性片| 欧美日韩综合另类| 午夜国产精品影院在线观看| 久久久久国产精品一区| 亚洲大黄网站| 欧美视频日韩视频| 亚洲欧美综合国产精品一区| 久久一区二区视频| 亚洲久久一区| 国产精品家庭影院| 欧美在线影院| 亚洲国产精品123| 亚洲一区欧美激情| 国内精品视频666| 欧美黑人在线观看| 亚洲综合丁香| 亚洲电影视频在线| 亚洲一区国产视频| 永久91嫩草亚洲精品人人| 欧美大片一区| 午夜日韩激情| 欧美aⅴ一区二区三区视频| 亚洲另类视频| 国产综合av| 欧美人牲a欧美精品| 亚洲欧美日韩精品久久久久| 欧美激情第4页| 欧美在线观看视频在线| 亚洲伦伦在线| 国语自产精品视频在线看| 欧美日本久久| 欧美中文字幕在线播放| 欧美激情精品久久久久久蜜臀| 亚洲图片激情小说| 亚洲国产成人精品久久| 国产欧美一区二区三区沐欲| 欧美激情二区三区| 久久久久国产精品人| 亚洲午夜黄色| 亚洲美女中出| 欧美激情精品久久久久久| 久久精品国产免费看久久精品| 在线一区欧美| 亚洲精品在线免费| 影音先锋一区| 国产一区二区三区日韩| 国产精品v日韩精品v欧美精品网站| 蜜臀av一级做a爰片久久| 久久久精品欧美丰满| 午夜在线一区| 午夜影院日韩| 亚洲欧美一区二区精品久久久|