zoj 1940 模拟三维bfs
来源:互联网 发布:python lxml etree 编辑:程序博客网 时间:2024/06/04 19:43
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!
题解:题目很吓人,但其实是个水题,也是裸的bfs
#include <iostream>#include <cstdio>#include <algorithm>#include <queue>using namespace std;int l,r,c;char mp[40][40][40];int sx,sy,sz,ex,ey,ez;int disx[6]={1,-1,0,0,0,0};int disy[6]={0,0,0,0,-1,1};int disz[6]={0,0,1,-1,0,0};const int inf=9999999;int ans;struct node { int x,y,z; int step;};int check(int x,int y,int z) { if(x<0||y<0||z<0||x>=l||y>=r||z>=c) return 1; if(mp[x][y][z]=='#') return 1; return 0;}void bfs() { queue<node> q; node a,next; a.x=sx; a.y=sy; a.z=sz; a.step=0; q.push(a); mp[sx][sy][sz]='#'; while(!q.empty()) { a=q.front();q.pop(); if(a.x==ex&&a.y==ey&&a.z==ez) if(a.step<=ans) ans=a.step; for(int i=0;i<6;i++) { next.x=a.x+disx[i]; next.y=a.y+disy[i]; next.z=a.z+disz[i]; next.step=a.step+1; if(check(next.x,next.y,next.z)) continue; mp[next.x][next.y][next.z]='#'; q.push(next); } }}int main() {// freopen("input.txt","r",stdin); while(scanf("%d%d%d",&l,&r,&c)!=EOF) { if(l==0&&r==0&&c==0) break; for(int i=0;i<l;i++) { for(int j=0;j<r;j++) { scanf("%s",mp[i][j]); } } for(int i=0;i<l;i++) { for(int j=0;j<r;j++) { for(int x=0;x<c;x++) { if(mp[i][j][x]=='S') { sx=i; sy=j; sz=x; } if(mp[i][j][x]=='E') { ex=i; ey=j; ez=x; } } } } ans=inf; bfs(); if(ans==inf) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n",ans); } return 0;}
- zoj 1940 模拟三维bfs
- ZOJ 2928 模拟退火 求三维费马点
- ZOJ 3814:模拟和状态压缩BFS
- ZOJ 3781-缩点+bfs模拟
- 三维bfs
- zju 1940 Dungeon Master(三维BFS暴搜题)
- ZOJ 1940 Dungeon Master 【BFS】
- zoj 1940 Dungeon Master(BFS)
- ZOJ 1940 Dungeon Master bfs
- ZOJ 1005 Jugs(模拟 special judge,也可以BFS)
- ZOJ 3446 Doraemon's Battle (三维dp+BFS)【打怪类模板】
- hdu 1253 三维bfs
- poj 2251 三维BFS
- HDU 1240 三维bfs
- hdu 1240 三维BFS
- HDU1253(BFS+三维)
- 0.8poj2252(bfs三维)
- poj2225Asteroids!(三维BFS)
- 开通博客-贴吧6000回复的继续
- 【HDU 1074 Doing Homework】+ 状压dp
- 网站设置缓存的问题
- [BZOJ1242]抢修道路
- 机器人视觉—以箱子为目标的跟踪检测
- zoj 1940 模拟三维bfs
- 【内功篇】指针&数组&字符串(五)
- 在servlet 中使用 request.getSession().getServletContext().getRealPath("upload/" ); 获取不到 tomcat 服务器目录
- STM32F767+TB6600+57步进电机
- Java中自写LinkedList,掌握底层结构
- Tensorflow中关于Tensor和Variable的理解
- Python用filter()滤掉非回数
- 学习c语言指针的一些小知识
- 最小子串覆盖