poj2251-dungeon master(bfs广搜)
来源:互联网 发布:linux基本命令使用 编辑:程序博客网 时间:2024/04/25 23:47
复制题目过来的时候出现了不可调和的错误,又貼链接吧
poj2251
这个题目是平面迷宫的一个拓展问题,不过并没有实质性的突破,只是变成了三维的而已,多加了个上下楼。因此照着深搜的框架写就可以了。但我在写的时候出现了诸多bug,比如赋值的时候写了两个等号,标记走过的路线就失效了,把所有路线都往队列里压,结果就MLE了,题目给的数据范围是30,但讨论区里有人开到一百多才过,我的测试31就可以过了。
代码是老套路,不解释了
#include<iostream>#include<queue>#include<cstring>#include<cstdlib>#include<cstdio>using namespace std;const int sz = 110;char maze[sz][sz][sz];int l, r, c;int dir[6][3] = {{0,1,0},{0,0,1},{0,0,-1},{0,-1,0},{1,0,0},{-1,0,0}};struct point{ int x, y, z, step;}now, next;queue<point> q;bool vtd[sz][sz][sz];bool inside_x(int x){ if(x >= 0 && x < l) return true; return false;}bool inside_y(int x){ if(x >= 0 && x < r) return true; return false;}bool inside_z(int x){ if(x >= 0 && x < c) return true; return false;}int bfs(int x, int y, int z, int step){ while(!q.empty()) q.pop(); now.x = x, now.y = y, now.z = z, now.step = step; q.push(now); vtd[x][y][z] = true; while(!q.empty()) { now = q.front(); q.pop(); next = now; for(int i = 0; i < 6; i ++) { next.x = now.x + dir[i][0]; next.y = now.y + dir[i][1]; next.z = now.z + dir[i][2]; if(maze[next.x][next.y][next.z] == '#' || !inside_x(next.x) || !inside_y(next.y) || !inside_z(next.z)) continue; if(vtd[next.x][next.y][next.z]) { continue; } if(maze[next.x][next.y][next.z] == 'E') return next.step + 1; next.step = now.step + 1; vtd[next.x][next.y][next.z] = true; q.push(next); } } return -1;}int main(){ // freopen("output.txt","r",stdin); while(scanf("%d%d%d", &l, &r, &c)) { if(l == 0) break; int res; point start; int findStart = 1; memset(vtd,false,sizeof(vtd)); memset(maze,0,sizeof(maze)); for(int i = 0; i < l; i ++) { for(int j = 0; j < r; j ++) { scanf("%s", &maze[i][j]); if(findStart) for(int k = 0; k < c; k ++) { if(maze[i][j][k] == 'S') { start.x = i; start.y = j; start.z = k; findStart = 0; } } } } res = bfs(start.x,start.y,start.z,0); if(res > 0) printf("Escaped in %d minute(s).\n", res); else cout << "Trapped!" << endl; }}
0 0
- poj2251-dungeon master(bfs广搜)
- POJ2251--Dungeon Master--广搜
- POJ2251 Dungeon Master(三维广搜BFS+优先队列)
- 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】
- 关于CoreData的整理
- bzoj-4196 NOI-2015 软件包管理器
- Docker入门教程(一)介绍
- 打包jar文件以及运行jar时的注意点
- 股票学习36(公司财务分析)
- poj2251-dungeon master(bfs广搜)
- linux页表创建与更新
- Django应用部署 - 上线指南
- Oracle存储过程和存储函数的区别
- 当累的时候该怎么去调节
- fastreport 转PDF 中文 乱码 ARIAL
- 架构师速成7.5-性能优化为什么写的这么晚?
- maven的package与install命令区别
- Docker学习笔记(2)--Docker常用命令