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

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>
            国产老女人精品毛片久久| 亚洲欧美日韩精品久久亚洲区 | 欧美四级在线观看| 欧美激情一区二区三区高清视频| 中日韩美女免费视频网站在线观看| 欧美激情二区三区| 91久久久亚洲精品| 亚洲自啪免费| 欧美午夜一区二区福利视频| 欧美日韩精品一区二区天天拍小说 | 久久精品国产精品 | 亚洲综合国产| 亚洲影院污污.| 久久久久国产一区二区三区| 久久一本综合频道| 午夜日韩在线观看| 久久久噜噜噜久噜久久| 亚洲视频大全| 亚洲一二三级电影| 亚洲欧美综合另类中字| 免费不卡亚洲欧美| 夜夜嗨av一区二区三区网页| 亚洲一区免费在线观看| 另类天堂av| 国产无一区二区| 日韩午夜激情av| 美国十次成人| 欧美亚洲在线视频| 欧美日韩国产综合视频在线观看中文 | 亚洲人www| 久久黄色级2电影| 国产精品日韩久久久| 亚洲精品偷拍| 欧美激情网站在线观看| 午夜亚洲福利| 国产精品视频| 亚洲小说春色综合另类电影| 欧美一站二站| 亚洲尤物在线视频观看| 亚洲三级影院| 欧美中日韩免费视频| 欧美华人在线视频| 亚洲欧美中文另类| 亚洲国内自拍| 亚洲欧美国产日韩中文字幕| 欧美综合国产精品久久丁香| 欧美精品久久一区二区| 国产真实乱子伦精品视频| 一本色道久久99精品综合| 亚洲二区三区四区| 欧美日韩三区四区| 一本久久a久久免费精品不卡| 久久久97精品| 欧美一级黄色网| 国产中文一区| 欧美a级片网站| 免费美女久久99| 亚洲黄色成人| 一区二区高清在线| 欧美偷拍另类| 久久精品国产第一区二区三区| 中文欧美字幕免费| 国产精品夜夜嗨| 久久最新视频| 亚洲黄色视屏| 国产一区日韩一区| 女人天堂亚洲aⅴ在线观看| 久久先锋影音| 亚洲校园激情| 久久精品亚洲国产奇米99| 国产精品稀缺呦系列在线| 美女啪啪无遮挡免费久久网站| 你懂的国产精品| 欧美中文字幕| 欧美日韩一区二区三区四区在线观看| 樱花yy私人影院亚洲| 午夜久久资源| 亚洲一二三区在线| 久久精品亚洲| 亚洲永久精品国产| 美女日韩在线中文字幕| 欧美一级在线视频| 欧美激情一区二区三区全黄| 亚洲精品免费网站| 欧美成人小视频| 久久精品首页| 国产精品高潮呻吟| 亚洲高清二区| 91久久国产自产拍夜夜嗨| 亚洲视频在线观看三级| 日韩一区二区免费看| 欧美成人一区二区三区在线观看| 久久精品五月| 国产色综合网| 香蕉国产精品偷在线观看不卡 | 午夜日本精品| 欧美好骚综合网| 欧美国产日本韩| 91久久久久久国产精品| 麻豆av福利av久久av| 欧美激情一区二区三级高清视频| 91久久久久久| 欧美日韩一区在线观看| 欧美91大片| 夜夜狂射影院欧美极品| 欧美日韩在线三区| 亚洲视频导航| 欧美成人首页| 正在播放欧美视频| 国产一区二区三区四区hd| 可以看av的网站久久看| 夜夜嗨av一区二区三区网页| 久久久久久久999精品视频| 18成人免费观看视频| 国产精品激情偷乱一区二区∴| 午夜精品久久久久久久白皮肤| 久久青草欧美一区二区三区| 日韩午夜免费| 亚洲电影免费观看高清完整版在线观看 | 国产精品爱啪在线线免费观看| 欧美aⅴ一区二区三区视频| 在线一区日本视频| 国产视频在线观看一区二区| 欧美3dxxxxhd| 欧美一区午夜精品| 亚洲一区二区三区在线观看视频| 乱码第一页成人| 久久国产88| 激情综合电影网| 国产视频在线观看一区| 国产精品毛片| 国产精品一区=区| 国产伦精品一区二区三| 你懂的成人av| 国产精品女主播| 国产人成精品一区二区三| 国产日韩精品一区二区三区 | 欧美日韩一区二区免费在线观看 | 国语自产精品视频在线看一大j8| 欧美日韩亚洲不卡| 国产精品尤物福利片在线观看| 欧美华人在线视频| 欧美精品七区| 国产色产综合产在线视频| 欧美亚一区二区| 国产精品人人爽人人做我的可爱| 国产精品人成在线观看免费| 国产亚洲福利| 亚洲视频在线播放| 欧美黄免费看| 亚洲影视中文字幕| 午夜精彩国产免费不卡不顿大片| 欧美一区成人| 久久爱www.| 亚洲一区二区在线观看视频| 久久美女性网| 欧美成人资源| 国产精品美女视频网站| 黑人巨大精品欧美黑白配亚洲| 夜夜嗨av一区二区三区网页| 欧美亚洲在线观看| 一本色道久久综合亚洲精品不卡| 久久这里只精品最新地址| 亚洲精品美女在线观看播放| 亚洲茄子视频| 另类成人小视频在线| 国产综合精品| 亚洲成人中文| 麻豆九一精品爱看视频在线观看免费| 国产精品午夜电影| 亚洲一二区在线| 日韩视频一区二区| 欧美一二三视频| 亚洲国产精品久久| 亚洲精品久久久久久一区二区 | 国产一区成人| 欧美激情区在线播放| 美女爽到呻吟久久久久| 一本大道av伊人久久综合| 亚洲天堂成人在线视频| 国产亚洲永久域名| 免费试看一区| 久久综合久久综合久久| 亚洲欧美国产高清| 欧美一区二粉嫩精品国产一线天| 韩国欧美一区| 亚洲精品国产精品乱码不99 | 亚洲精品1234| 亚洲人午夜精品免费| 国产精品成人在线| 久色成人在线| 久久综合激情| 麻豆成人精品| 国产精品永久免费在线| 亚洲欧洲日本一区二区三区| 国产欧美在线观看| 99视频有精品| 亚洲精品乱码久久久久久蜜桃91| 午夜欧美大尺度福利影院在线看| 99精品欧美一区|