L
来源:互联网 发布:淘宝虚拟充值软件 编辑:程序博客网 时间:2024/04/28 14:15
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走到d看能不能走到,能就输出分钟,其实就是步数
分析:
就是简单的八皇后变形,用宽搜就行
代码:
#include<iostream>#include<stdio.h>#include<queue>#include<algorithm>#include<math.h>#include<cstring>using namespace std;struct num{ int x,y,z,second;};int a[6][3]={1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,-1,0,0,1};int b[35][35][35],L,R,C,n,m,k;int bfs(int q,int w,int p){ queue<num>v; int i; num d,l; d.x=q; d.y=w; d.z=p; d.second=0; v.push(d); while(!v.empty()) { d=v.front(); v.pop(); for(i=0;i<6;i++) { q=d.x+a[i][0]; w=d.y+a[i][1]; p=d.z+a[i][2]; if(!b[q][w][p]&&q>=1&&q<=L&&w>=1&&w<=R&&p>=1&&p<=C) { if(q==n&&w==m&&p==k) return d.second+1; l.x=q; l.y=w; l.z=p; b[q][w][p]=1; l.second=d.second+1; v.push(l); } } } return -1;}int main(){ int i,j,f,xx,yy,zz,tt=0; char ff; while(cin>>L>>R>>C&&L&&R&&C) { memset(b,0,sizeof(b)); for(i=1;i<=L;i++) for(j=1;j<=R;j++) for(f=1;f<=C;f++){ cin>>ff; if(ff=='#')b[i][j][f]=1; else if(ff=='S'){b[i][j][f]=1;xx=i;yy=j;zz=f;} else if(ff=='E'){n=i;m=j;k=f;} } tt=bfs(xx,yy,zz); if(tt==-1)cout<<"Trapped!"<<endl; else cout<<"Escaped in "<<tt<<" minute(s)."<<endl; }}
感受:
挺简单的。。。。。
阅读全文
0 0
- l
- .,l
- l
- l
- l
- ';l
- L
- l【
- ,l,
- L
- l
- L
- L
- L
- L
- L
- L
- L
- 58. Length of Last Word
- 28335 cmd文件
- C语言下的静态顺序表
- stdout和stderr的趣味问题
- 2017年河南省ACM省赛 Problem A: 谍报分析
- L
- android Bitmap和Drawable的区别
- ARM推出基于DynamIQ技术的处理器,从端到云加速人工智能体验
- 队列
- 后台添加一本新图书的Servlet 代码
- 深入浅出AngularJs中的Service
- Hadoop入门案例(一) wordcount
- bzoj1457: 棋盘游戏
- [3]深度学习和Keras----Keras深度学习框架入门例子