国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 洪雅县| 静安区| 汝阳县| 元阳县| 左权县| 合川市| 藁城市| 微山县| 长武县| 兰西县| 屏南县| 新化县| 徐汇区| 宁城县| 法库县| 桦南县| 大新县| 毕节市| 库车县| 长武县| 临泉县| 思茅市| 鄂尔多斯市| 凭祥市| 木兰县| 确山县| 江油市| 观塘区| 襄垣县| 平乐县| 宣威市| 庄浪县| 沙河市| 乐都县| 米林县| 当涂县| 曲松县| 应用必备| 会东县| 岳普湖县| 宝山区|