POJ2251Dungeon Master
来源:互联网 发布:mac的鼠标不能按右键 编辑:程序博客网 时间:2024/05/17 16:13
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 35193 Accepted: 13450
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!
Source
Ulm Local 1997
题目的意思是给一个三维迷宫,求最短路
bfs暴力
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;#define MAXN 500char mp[35][35][35];bool vis[35][35][35];int dir[6][3]= {{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};struct node{ int x,y,z,cnt;};int m,n,h;bool check(node d){ if(d.x<0||d.x>=h||d.y<0||d.y>=m||d.z<0||d.z>=n||mp[d.x][d.y][d.z]=='#') return 0; return 1;}int bfs(int si,int sj,int sk,int di,int dj,int dk){ queue<node>q; memset(vis,0,sizeof vis); node f,d; f.x=si,f.y=sj,f.z=sk,f.cnt=0; q.push(f); vis[f.x][f.y][f.z]=1; while(!q.empty()) { f=q.front(); q.pop(); if(f.x==di&&f.y==dj&&f.z==dk) return f.cnt; for(int i=0; i<6; i++) { d.x=f.x+dir[i][0]; d.y=f.y+dir[i][1]; d.z=f.z+dir[i][2]; if(check(d)&&!vis[d.x][d.y][d.z]) { vis[d.x][d.y][d.z]=1; d.cnt=f.cnt+1; q.push(d); } } } return -1;}int main(){ int si,sj,sk,di,dj,dk; while(~scanf("%d%d%d",&h,&m,&n)&&(h+m+n)) { for(int i=0; i<h; i++) for(int j=0; j<m; j++) { scanf("%s",&mp[i][j]); for(int k=0; k<n; k++) if(mp[i][j][k]=='S') si=i,sj=j,sk=k; else if(mp[i][j][k]=='E') di=i,dj=j,dk=k; } int ans=bfs(si,sj,sk,di,dj,dk); if(ans!=-1) printf("Escaped in %d minute(s).\n",ans); else printf("Trapped!\n"); } return 0;}
阅读全文
0 0
- POJ2251Dungeon Master
- poj2251Dungeon Master bfs
- poj2251Dungeon Master【BFS】
- POJ2251Dungeon Master(AC)
- 【简单搜索】POJ2251Dungeon Master
- POJ2251Dungeon Master(bfs)
- POJ2251Dungeon Master&&nyoj523亡命逃窜
- POJ2251Dungeon Master(三维图)(BFS)
- poj2251Dungeon Master(三维bfs)
- POJ2251Dungeon Master(图搜)(三维bfs)
- POJ2251Dungeon Master(3D bfs)
- Master-Master Master-slave 区别
- master to master replication
- MongoDB Master+Master同步
- Master-Master架构
- Dual Master 复制架构(Master-Master)
- Dual Master 复制架构(Master-Master)
- Master Data
- c/c++整理--c++继承
- 交互软件的登录界面
- <划重点的Unity2017> 人物相关的物理系统组件详述
- Struts 2(初步)
- JavaScript学习重点
- POJ2251Dungeon Master
- Laravel 前台注册 阿里大于
- KMP总结
- Centos7安装vim8.0 + YouCompleteMe
- multiset<int, greater<int>> test 相关
- 欢迎使用CSDN-markdown编辑器
- POJ 2965 The Pilots Brothers' refrigerator(枚举+dfs)
- js技术--BOM(open,close,右下角固定悬浮框)
- python re模块