poj2251 Dungeon Master(BFS)
来源:互联网 发布:mac怎么添加铃声 编辑:程序博客网 时间:2024/03/29 14:20
Dungeon Master
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 17256 Accepted: 6721
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
/*昨天晚上做的。。Time:2014-12-29 7:23*/#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespace std;const int MAX=32;char g[MAX][MAX][MAX];struct Node{ int x,y,z; int steps; friend bool operator<(Node a,Node b){ return a.steps>b.steps; }}s,e;int move[6][3]={{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};int L,R,C;bool Judge(Node p){ if(p.x>=0&&p.x<C&&p.y>=0&&p.y<R&&p.z>=0&&p.z<L) return true; return false;}bool BFS(Node s){ priority_queue<Node>pq; pq.push(s); Node cur,temp; while(!pq.empty()){ cur=pq.top();pq.pop(); //printf("z=%d y=%d x=%d\n",cur.z,cur.y,cur.x); if(cur.x==e.x&&cur.y==e.y&&cur.z==e.z) { e.steps=cur.steps; return true; } for(int i=0;i<6;i++){ temp=cur; temp.x+=move[i][0]; temp.y+=move[i][1]; temp.z+=move[i][2]; /*if(cur.z==1&&cur.y==3&&cur.x==4){ printf("temp z=%d temp y=%d temp x=%d\n",temp.z,temp.y,temp.x); printf("%c\n",g[temp.z][temp.y][temp.x]); }*/ if(g[temp.z][temp.y][temp.x]=='.'&&Judge(temp)){ temp.steps++; pq.push(temp); g[temp.z][temp.y][temp.x]='#'; } } } return false;}int main(){ while(scanf("%d%d%d",&L,&R,&C)!=EOF){ //memset(g,0,sizeof(g)); if(L==0&&R==0&&C==0) break; for(int i=0;i<L;i++){ for(int j=0;j<R;j++){ scanf("%s",g[i][j]); //puts(g[i][j]); for(int k=0;k<C;k++){ if(g[i][j][k]=='S'){ s.z=i;s.y=j;s.x=k; //printf("sz=%d sy=%d sx=%d\n",s.z,s.y,s.x); s.steps=0; g[i][j][k]='#'; } if(g[i][j][k]=='E'){ e.z=i;e.y=j;e.x=k; g[i][j][k]='.'; // printf("ez=%d ey=%d ex=%d\n",e.z,e.y,e.x); } } } } if(BFS(s)){ printf("Escaped in %d minute(s).\n",e.steps); }else{ printf("Trapped!\n"); } }return 0;}
0 0
- 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)
- POJ2251 Dungeon Master(BFS)
- POJ2251-Dungeon Master-BFS
- 【POJ2251】Dungeon Master(bfs)
- poj2251-bfs- Dungeon Master
- POJ2251 Dungeon Master 【BFS】
- POJ2251:Dungeon Master(BFS)
- Dungeon Master(poj2251,bfs)
- POJ2251 Dungeon Master 三维BFS
- 当前我国高职教育经济功能的合理性分析
- Qt Quick里的AnimatedSprite的用法
- Java英文单词Java基础常见英语词汇
- Qt学习之路之模型
- BZOJ 3823 定情信物 线性筛乘法逆元
- poj2251 Dungeon Master(BFS)
- 支持RVM/VMM/UVM验证方法学+VCS/NC仿真器+Verdi的dumpfsdb的通用脚本文件
- ubuntu上安装运行Hadoop2.6
- 【BZOJ3823】【East!模拟赛_Round5T1】定情信物 推公式+线性筛逆元(推公式法比出题人简)
- 通过XShell 的SSH隧道功能, 让外网访问内网网站
- Filesystem-Hierarchy-Standard(FHS) 文件系统层次结构标准2.3中英对照版(未完待续)
- spring 4.1.3 单元测试时出现的NoSuchMethodError
- 12.29
- mysql-5.6.20-winx64.msi安装