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

首頁 > 學院 > 開發設計 > 正文

Dungeon Master [bfs]

2019-11-11 05:06:42
字體:
來源:轉載
供稿:網友

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!

解題報告

只要細心就是水題,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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 免费看黄色一级片 | 精品一区二区在线视频 | 精品69人人人人 | 亚洲天堂在线电影 | 成人做爰高潮片免费视频韩国 | 欧美性生交xxxxx久久久缅北 | 91精品国产毛片 | 69性欧美高清影院 | 久久久久久久久免费 | 13一14毛片免费看 | 美女亚洲综合 | 久久区二区 | 国产1区在线观看 | 蝌蚪久久窝 | 黄色av网站免费 | 亚洲一区久久久 | 亚洲精品在线观看免费 | 久久精品一区二区三区四区五区 | www.91sese| 成人18在线 | 色玖玖综合 | 欧美特级一级毛片 | 国产一区二区视频在线播放 | 在线成人看片 | 国产精品一区在线观看 | 视频一区二区视频 | 毛片免费观看日本中文 | 精品亚洲夜色av98在线观看 | 欧产日产国产精品v | 91精品一区二区综合在线 | 成人nv在线观看 | 欧美一级高清免费 | 成人在线视频国产 | 黄色免费av网站 | 最新中文在线视频 | 欧美成人黄色 | 欧美日本在线视频 | 国产女同疯狂激烈互摸 | 狠狠干五月 | 蜜桃传媒视频麻豆第一区免费观看 | 国产色91|