国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

POJ 2251(WA)

2019-11-08 01:41:23
字體:
供稿:網(wǎng)友

POJ 2251 Dungeon Master

三維簡單BFS

You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.         Is an escape possible? If yes, how long will it take?

Input    The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).L is the number of levels making up the dungeon. R and C are the number of rows and columns making up the plan of each level. Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are rePResented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.   OutputEach maze generates one line of output. If it is possible to reach the exit, print a line of the form    Escaped in x minute(s).where x is replaced by the shortest time it takes to escape. If it is not possible to escape, print the line    Trapped! Sample Input3 4 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0Sample Output Escaped in 11 minute(s).Trapped!很簡單很簡單的BFS,但是迷之WA了…暫時找不出錯誤,記錄一下這道題,過幾天再看看哪里錯了。錯誤的代碼↓
#include<stdio.h>#include<queue>#include<string.h>using namespace std;int L,R,C;typedef struct{    int x,y,z;}node;node S,E;node IN,OUT;queue<node> Q;char dun[35][35][35];bool vis[35][35][35];int dis[35][35][35];int dx[6]={1,-1,0,0,0,0},    dy[6]={0,0,1,-1,0,0},    dz[6]={0,0,0,0,1,-1};int bfs(){    int i,j,k;    while(!Q.empty()){        OUT=Q.front();        Q.pop();        for(i=0;i<6;i++){            IN.x=OUT.x+dx[i];            IN.y=OUT.y+dy[i];            IN.z=OUT.z+dz[i];            if(IN.x>=L||IN.x<0||IN.y>=R||IN.y<0||IN.z>=C||IN.z<0)                continue;            if(vis[IN.x][IN.y][IN.z]==1)                continue;            dis[IN.x][IN.y][IN.z]=dis[OUT.x][OUT.y][OUT.z]+1;            if(dun[IN.x][IN.y][IN.z]=='E'){                return 0;            }            vis[IN.x][IN.y][IN.z]=1;            Q.push(IN);        }    }    return 0;}int main(){    int i,j,k;    char store;    while(scanf("%d %d %d",&L,&R,&C)!=EOF){        if(L==0&&R==0&&C==0)            break;        for(i=0;i<L;i++){            for(j=0;j<R;j++){                scanf("%s",dun[i][j]);            }            scanf("%c",&store);        }        while(!Q.empty())            Q.pop();        memset(dis,-1,sizeof(dis));        for(i=0;i<L;i++){            for(j=0;j<R;j++){                for(k=0;k<C;k++){                    if(dun[i][j][k]=='S'){                        S.x=i;                        S.y=j;                        S.z=k;                    }                    if(dun[i][j][k]=='E'){                        E.x=i;                        E.y=j;                        E.z=k;                    }                    if(dun[i][j][k]=='#')                        vis[i][j][k]=1;                    if(dun[i][j][k]=='.')                        vis[i][j][k]=0;                }            }        }        dis[S.x][S.y][S.z]=0;        vis[S.x][S.y][S.z]=1;        Q.push(S);        bfs();        if(dis[E.x][E.y][E.z]==-1)            printf("Trapped!/n");        else            printf("Escaped in %d minute(s)./n",dis[E.x][E.y][E.z]);    }    return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 汶川县| 普兰店市| 睢宁县| 鄂伦春自治旗| 长宁区| 南木林县| 垫江县| 两当县| 辉南县| 苏尼特左旗| 万州区| 五台县| 来宾市| 读书| 寻甸| 名山县| 施甸县| 讷河市| 米泉市| 澄迈县| 瑞安市| 南投县| 锡林郭勒盟| 民乐县| 武宣县| 连江县| 长兴县| 晴隆县| 若尔盖县| 嘉兴市| 黄石市| 高碑店市| 南郑县| 锡林浩特市| 盐津县| 遂昌县| 清丰县| 晋中市| 武汉市| 阳新县| 延吉市|