poj2251--Dungeon Master(搜索练习3-三维bfs)
来源:互联网 发布:windows version 1703 编辑:程序博客网 时间:2024/05/27 09:46
Dungeon Master
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Appoint description:
Description
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?
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.
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
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
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 <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std ;char str[32][32][32] ;struct node{ int l , r , c , step ;};queue <node> que ;int vis[32][32][32] ;int a[8][3] = { {-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1} } ;int main(){ int l , r , c , k , i , j ; node p , q ; while( scanf("%d %d %d", &l, &r, &c) != EOF ) { if( l == 0 && r == 0 && c == 0 ) break ; memset(vis,0,sizeof(vis)) ; for(k = 0 ; k < l ; k++) { for(i = 0 ; i < r ; i++) { scanf("%s", str[k][i]) ; for(j = 0 ; j < c ; j++) if( str[k][i][j] == 'S' ) { p.l = k ; p.r = i ; p.c = j ; p.step = 0 ; } } } vis[ p.l ][ p.r ][ p.c ] = 1; while( !que.empty() ) que.pop() ; que.push(p) ; while( !que.empty() ) { p = que.front() ; if( str[ p.l ][ p.r ][ p.c ] == 'E' ) break ; que.pop() ; for(i = 0 ; i < 8 ; i++) { q = p ; q.l += a[i][0] ; q.r += a[i][1] ; q.c += a[i][2] ; if( q.l >= 0 && q.l < l && q.r >= 0 && q.r < r && q.c >= 0 && q.c < c && str[q.l][q.r][q.c] != '#' && vis[q.l][q.r][q.c] == 0 ) { vis[q.l][q.r][q.c] = 1 ; q.step++ ; que.push(q) ; } } } if( str[ p.l ][ p.r ][ p.c ] == 'E' ) printf("Escaped in %d minute(s).\n", p.step) ; else printf("Trapped!\n") ; } return 0;}
0 0
- poj2251--Dungeon Master(搜索练习3-三维bfs)
- POJ2251 Dungeon Master 三维BFS
- 三维BFS poj2251 Dungeon Master
- POJ2251-Dungeon Master (三维BFS)
- POJ2251:Dungeon Master(BFS)3D搜索
- POJ2251 Dungeon Master(搜索BFS)
- poj2251 Dungeon Master(三维bfs)
- Dungeon Master 三维搜索(bfs)
- poj2251 Dungeon Master (BFS)
- Dungeon Master(poj2251,bfs)
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master bfs
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master(BFS)
- POJ2251 Dungeon Master BFS
- [bfs]poj2251 Dungeon Master
- poj2251 dungeon master【BFS】~
- POJ2251 Dungeon Master(bfs)
- 1、JavaScript中的单引号、双引号的测试
- nyoj 860 又见01背包 【01-背包变形】
- android蓝牙开发---与蓝牙模块进行通信
- Snowflake Snow Snowflakes寻找相似雪花
- 二叉树的非递归遍历
- poj2251--Dungeon Master(搜索练习3-三维bfs)
- 设计模式--观察者模式
- 自定义Access-Control-Allow-Origin策略以解决字体文件跨域权限问题
- 利用aircrack-ng工具获取附近wifi的密码
- MTD设备驱动
- leetcode_Roman to Integer_easy_可以看看方法
- C# winform对话框用法大全
- 1018. 锤子剪刀布
- Facebook 推出 App Links 开发者工具意在解决什么问题?