NYOJ-353 3D地图搜索
来源:互联网 发布:山东广电网络集团官网 编辑:程序博客网 时间:2024/06/16 07:36
3D dungeon
时间限制:1000 ms | 内存限制:65535 KB难度:2
描述
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?
输入
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.
输出
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!
样例输入
3 4 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0
样例输出
Escaped in 11 minute(s).Trapped!
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<queue>using namespace std;const int maxn = 35;typedef struct node{ int z,x,y; int step; //bool operator < (const node &a)const //{ // return step>a.step; //}}point;point start;int dir[6][3]={0,1,0,0,0,1,0,-1,0,0,0,-1,1,0,0,-1,0,0};char maze[maxn][maxn][maxn]; //3维地图。int vis[maxn][maxn][maxn];int height,row,col;void init(){ memset(maze,0,sizeof(maze)); memset(vis,0,sizeof(vis)); for(int i=0;i<height;i++) for(int j=0;j<row;j++) scanf("%s",maze[i][j]); for(int i=0;i<height;i++) for(int j=0;j<row;j++) for(int k=0;k<col;k++) if(maze[i][j][k]=='S') start={i,j,k,0};}int bfs(){ queue<point> qu; qu.push(start); vis[start.z][start.x][start.y]=1; while(!qu.empty()) { point v=qu.front(); qu.pop(); if(maze[v.z][v.x][v.y]=='E') return v.step; for(int i=0;i<6;i++) { int mz=v.z+dir[i][0]; int mx=v.x+dir[i][1]; int my=v.y+dir[i][2]; if(mz<0||mx<0||my<0||mz>=height||mx>=row||my>=col||vis[mz][mx][my]||maze[mz][mx][my]=='#') continue; vis[mz][mx][my]=1; point to={mz,mx,my,v.step+1}; qu.push(to); } } return -1;}int main(){ while(~scanf("%d%d%d",&height,&row,&col),height||row||col) { init(); int ans = bfs(); if(ans == -1) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n",ans); } return 0;}
阅读全文
0 0
- NYOJ-353 3D地图搜索
- 微软推出三维立体地图搜索(3-D City Live Search)
- NYOJ 353 3D dungeon
- NYOJ 353-3D dungeon
- NYOJ 353 3D dungeon
- 地图搜索
- 地图搜索
- NYOJ 353 3D dungeon 【bfs】
- nyoj 353 3D dungeon 【bfs】
- NYOJ 353--3D dungeon【水题 && BFS】
- NYOJ 353 3D dungeon (BFS)
- nyoj 353 3d dundeon【bfs】
- nyoj 353 3D dungeon 【bfs】
- NYOJ 353 3D dungeon + zoj 1940 Dungeon Master
- NYOJ题目353 3D dungeon(BFS)
- NYOJ 353 3D dungeon(三维数组BFS)
- nyoj 353 3D dungeon 【BFS基础题】
- NYOJ--353--bfs+优先队列--3D dungeon
- Algorithm头文件中的sort函数使用
- C++随记(一)---字符串数组的输入问题
- faster rcnn解析之stage1_rpn_solver60k80k.pt
- PHP面试之文件夹下内容重复的文件去重
- IO输出输入流
- NYOJ-353 3D地图搜索
- C++字符串数组
- 360浏览器下自动填写用户名密码惹祸了
- Count of Smaller Numbers After Self
- POJ2676
- SPOJ
- androidSudio学习网站
- 18、vue.js 之路由钩子函数
- 算法作业_24(2017.5.23第十四周)