poj 2251 Dungeon Master
来源:互联网 发布:软件类型分类 编辑:程序博客网 时间:2024/06/05 14:28
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16305 Accepted: 6323
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!
题意:S为被关的地方E是出口输出逃出的最短时间如果逃不出来(即到E没有通路)输出Trapped!
利用广搜解题 这是一个三维的地图 Map【i】【j】【k】i表示第几层j表示第几行k表示第几列
#include<stdio.h>#include<iostream>#include<string.h>#include<queue>using namespace std;struct node{ int x,y,z; int step;};char MAP[110][110][110];int vis[110][110][110];int dir[6][3]= {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};int n,r,l,f;node bfs(int i,int j,int k){ node p,m,t; p.x=i; p.y=j; p.z=k; p.step=0; queue<node>q; q.push(p); while(!q.empty()) { m=q.front(); q.pop(); if(MAP[m.x][m.y][m.z]=='E') { f=1; return m; } for(i=0; i<6; i++) { t.x=m.x+dir[i][0]; t.y=m.y+dir[i][1]; t.z=m.z+dir[i][2]; if(t.x>=1&&t.x<=n&&t.y>=1&&t.y<=r&&t.z>=1&&t.z<=l&&MAP[t.x][t.y][t.z]!='#'&&vis[t.x][t.y][t.z]==0) { p.x=t.x; p.y=t.y; p.z=t.z; p.step=m.step+1; //cout<<p.x<<p.y<<p.z<<p.step<<endl; vis[p.x][p.y][p.z]=1; q.push(p); } } }}int main(){ int i,j,k; node ans; while(cin>>n>>r>>l&&n!=0&&r!=0&&l!=0) { f=0; for(i=1; i<=n; i++) for(j=1; j<=r; j++) for(k=1; k<=l; k++) cin>>MAP[i][j][k]; /*for(i=1; i<=n; i++) { for(j=1; j<=r; j++) { for(k=1; k<=l; k++) cout<<MAP[i][j][k]; cout<<endl; } cout<<endl; }*/ memset(vis,0,sizeof(vis)); for(i=1; i<=n; i++) { for(j=1; j<=r; j++) { for(k=1; k<=l; k++) if(MAP[i][j][k]=='S') { //cout<<i<<j<<k<<endl; vis[i][j][k]=1; ans=bfs(i,j,k); } } } if(f==1) printf("Escaped in %d minute(s).\n",ans.step); else printf("Trapped!\n"); } return 0;}
0 0
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- Poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 Dungeon Master
- POJ-2251-Dungeon Master
- POJ 2251Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 - Dungeon Master
- POJ 2251 Dungeon Master
- POJ 2251 Dungeon Master
- POJ-2251-Dungeon Master
- poj 2251 Dungeon Master
- 通用(任何android机型)Root教程(完整版!附砖机自救方法)
- BP神经网络函数拟合
- 善待身边的每一个人
- hdu 1879 继续畅通工程(图论:最小生成树)
- MySQL 无法主从复制解决方法
- poj 2251 Dungeon Master
- Ubuntu 右键打开终端
- 64位操作系统下Visual Studio连接Oracle数据库 错误ORA-06413
- R语言实现数据抽样&创建训练集和测试集
- 【python】第六章——抽象
- 导航菜单(移动出现子菜单)
- TestLink环境搭建
- 动态规划第4讲——计数问题中的DP算法
- 并查集