麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Dungeon Master [bfs]

2019-11-11 05:03:26
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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.

Output

Each 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 Input

3 4 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0

Sample Output

Escaped in 11 minute(s).Trapped!

解題報(bào)告

只要細(xì)心就是水題,bfs走一遍即可

#include<stdio.h>#include<string.h>#include<queue>#define MAX_N 32using namespace std;typedef pair<int,int> P;bool map[MAX_N][MAX_N][MAX_N];int best[MAX_N][MAX_N][MAX_N];int s_x,s_y,s_t,e_x,e_y,e_t,H,W,T;int ox[]={0,0,0,1,-1};int oy[]={0,1,-1,0,0};int ot[]={0,1,-1};void bfs(){ memset(best,0x3f,sizeof(best)); queue<P> que; que.push(make_pair(s_x+s_y*H,s_t)); best[s_t][s_x][s_y]=0; while(!que.empty()){ int X=que.front().first%H,Y=que.front().first/H,now=que.front().second;que.pop(); int step=best[now][X][Y]; if(X==e_x&&Y==e_y&&now==e_t){ printf("Escaped in %d minute(s)./n",step); return ; } for(int i=0;i<5;i++){ int x=ox[i]+X; int y=oy[i]+Y; if(0<=x&&x<H&&0<=y&&y<W&&map[now][x][y]){ for(int u=0;u<3;u++){ int el=ot[u]+now; int r=ot[u]&&i>0?1:0; if(T>el&&el>=0&&map[el][x][y]&&best[el][x][y]>step+1+r){ best[el][x][y]=step+1+r; que.push(make_pair(x+y*H,el)); } } } } } puts("Trapped!");}int main(){ char str[32]; while(~scanf("%d%d%d",&T,&H,&W)&&T&&H&&W){ for(int t=0;t<T;t++) for(int i=0;i<H;i++){ scanf("%s",str); for(int j=0;j<W;j++){ switch(str[j]){ case 'S':s_x=i,s_y=j,s_t=t;map[t][i][j]=true;break; case 'E':e_x=i,e_y=j,e_t=t;map[t][i][j]=true;break; case '.':map[t][i][j]=true;break; case '#':map[t][i][j]=false;break; } } } bfs(); } return 0;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 草久在线观看视频 | 在线天堂中文在线资源网 | 粉嫩一区 | 在线亚洲欧美日韩 | 久久久婷婷一区二区三区不卡 | 91精品国产91久久久 | 精品一区二区三区在线视频 | 国产精品99久久免费观看 | 天天夜夜草 | 黄色毛片a级 | 久久羞羞| 爱操成人网 | 欧美伦交 | 欧美一级特黄aaaaaaa什 | 日本高清无遮挡 | 黑人操穴 | 欧美一级黄色片在线观看 | xxxxhd73国产| 久久精品女人天堂av | 干一夜综合| 国产91九色视频 | 久久国产免费视频 | 国产毛片在线 | 国产1区在线 | 免费观看一区二区三区 | 欧美18—19sex性护士中国 | 31freehdxxxx欧美 | omofun 动漫在线观看 | 一级做a爰性色毛片免费 | 国产视频在线观看一区二区三区 | 精品国产精品久久 | 国语自产免费精品视频在 | 日本成人一二三区 | 亚洲国产资源 | 91成人在线网站 | 精品久久久一二三区播放播放播放视频 | av手机在线免费播放 | 热99在线 | 日韩视频在线观看免费视频 | 精品久久9999 | 91色爱|