2251&[kuangbin带你飞]专题一 简单搜索 B
来源:互联网 发布:淘宝买快排警察找我 编辑:程序博客网 时间:2024/06/05 15:39
B - Dungeon Master
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?
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.
Output
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!
Sample Input
3 4 5
S….
.###.
.##..
###.#
#####
#####
##.##
##…
#####
#####
#.###
####E
1 3 3
S##
#E#
###
0 0 0
Sample Output
Escaped in 11 minute(s).
Trapped!
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;char ans[32][32][32];bool book[32][32][32];int l,r,c;int tx,ty,tz,fx,fy,fz;int cnt[8][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; int sum; friend bool operator < (Node a,Node b) { return a.sum>b.sum; }};bool check(int x,int flag) { if(x>=0&&x<flag) return true; return false;}int bfs() { Node now,next; priority_queue<Node>Q; while(!Q.empty()) Q.pop(); now.x=tx,now.y=ty,now.z=tz,now.sum=0; Q.push(now); book[tx][ty][tz]=false; while(!Q.empty()) { now=Q.top(); Q.pop(); if(now.x==fx&&now.y==fy&&now.z==fz) return now.sum; for(int i=0;i<6;i++) { next.x=now.x+cnt[i][0]; next.y=now.y+cnt[i][1]; next.z=now.z+cnt[i][2]; if(book[next.x][next.y][next.z]&&check(next.x,l)&&check(next.y,r)&&check(next.z,c)) { if(ans[next.x][next.y][next.z]!='#') { next.sum=now.sum+1; book[next.x][next.y][next.z]=false; Q.push(next); } } } } return 0;}int main(){ while(cin>>l>>r>>c&&l) { memset(book,true,sizeof(book)); for(int i=0;i<l;i++) { for(int j=0;j<r;j++) { for(int k=0;k<c;k++) { cin>>ans[i][j][k]; if(ans[i][j][k]=='S') tx=i,ty=j,tz=k; if(ans[i][j][k]=='E') fx=i,fy=j,fz=k; } } } int sum=bfs(); if(sum==0) cout<<"Trapped!"<<endl; else cout<<"Escaped in "<<sum<<" minute(s)."<<endl; } return 0;}
- 2251&[kuangbin带你飞]专题一 简单搜索 B
- [kuangbin带你飞]专题一 简单搜索 B POJ2251
- [kuangbin带你飞]专题一 简单搜索 B
- [kuangbin带你飞]专题一 简单搜索-B
- [kuangbin带你飞]专题一 简单搜索 B
- [kuangbin带你飞]专题一 简单搜索 B - Dungeon Master(POJ 2251)
- [kuangbin带你飞]专题1 简单搜索 B
- kuangbin带你飞专题一(搜索)B
- [kuangbin带你飞]专题一 简单搜索 B - Dungeon Master poj2251
- [kuangbin带你飞]专题一 简单搜索->B - Dungeon Master
- [kuangbin带你飞]专题一 简单搜索 - B - Dungeon Master
- [kuangbin神带你飞]专题一 简单搜索
- kuangbin带你飞 专题一 简单搜索 (题解)
- Fire Game [kuangbin带你飞]专题一 简单搜索
- [kuangbin带你飞]专题一 简单搜索 总结
- Kuangbin带你飞专题一 简单搜索
- [kuangbin带你飞]专题一 简单搜索 D - Fliptile
- [kuangbin带你飞]专题一 简单搜索-J - Fire!
- 用户读书喜好推荐数据分析
- java二维码生成 使用SSM框架 搭建属于自己的APP二维码合成、解析、下载
- 构建RESTful Web Service
- POJ 1001--Exponentiation
- PHP的闭包
- 2251&[kuangbin带你飞]专题一 简单搜索 B
- 对ARM9哈弗结构的认识
- NKOJ-3711 摆花<L特供版>
- 【JavaScript的逻辑操作符】
- 【OLED字模及串口调试工具】
- 实训笔记第十四天
- [LeetCode]617. Merge Two Binary Trees
- MISC
- NodeJs实现简单的静态web项目