Dungeon Master
来源:互联网 发布:软件测试的基本技能 编辑:程序博客网 时间:2024/04/27 14:17
Dungeon Master
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 22958Accepted: 8942
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<stdio.h>#include<string.h>#include<queue>#include<algorithm>using namespace std;struct node{int x,y,z,t;friend bool operator < (node a,node b){return a.t > b.t;//这句话要用花括号括着。 } }a,temp;int l,r,c;int dx[6]={0,1,0,-1,0,0};int dy[6]={1,0,-1,0,0,0};int dz[6]={0,0,0,0,1,-1};char map[100][100][100];int vis[100][100][100];int bfs(int x,int y,int z){priority_queue<node>q;a.x=x;a.y=y;a.z=z;a.t=0;q.push(a);vis[a.x][a.y][a.z]=1;while(!q.empty()){a=q.top();q.pop();if(map[a.x][a.y][a.z]=='E') return a.t;for(int i=0;i<6;i++){temp.x=a.x+dx[i];temp.y=a.y+dy[i];temp.z=a.z+dz[i];if(map[temp.x][temp.y][temp.z]!='#' && vis[temp.x][temp.y][temp.z]==0 && temp.x>=0 && temp.x<l && temp.y>=0 && temp.y<r && temp.z>=0 &&temp.z<c)// {temp.t = a.t + 1; q.push(temp); vis[temp.x][temp.y][temp.z]=1;}}}return -1;} int main(){while(scanf("%d%d%d",&l,&r,&c),l||r||c){int i,j,k;int x,y,z;memset(map,0,sizeof(map));memset(vis,0,sizeof(vis));for(i=0;i<l;i++){for(j=0;j<r;j++){scanf("%s",map[i][j]);for(k=0;k<c;k++){ if(map[i][j][k]=='S'){ x=i; y=j; z=k;}}}}int ans;if(map[x][y][z]=='E'){ans=0;printf("Escaped in %d minute(s).\n",ans);} else { ans=bfs(x,y,z); if(ans!=-1) printf("Escaped in %d minute(s).\n",ans); else printf("Trapped!\n"); }}return 0;}
0 0
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- Dungeon Master
- 《笨办法学Python》 第18课手记
- 简述UIViewControl之间的七种传值方式
- Matlab中Fuzzy Logic Controller使用注意
- 从头认识java-18.2 基本的线程机制(8)多线程的异常捕捉
- python项目之 爬取代理的ip地址
- Dungeon Master
- 点击某个标签以外位置执行
- 转移啦!
- 泛型集合处理约瑟夫环
- 线程condition(二)控制线程通知
- 机器学习公开课笔记(8):k-means聚类和PCA降维
- 【Android】获取控件的宽和高
- 关于每天的工作量,集中精力干一件事,其他时间就是玩,逐步完善自己的时间分配
- 关于maven的基本理解