POJ 2251.Dungeon Master(BFS)
来源:互联网 发布:高斯朴素贝叶斯 数据 编辑:程序博客网 时间:2024/04/28 19:22
题目传送门
三维搜索,多了一维也就是多了上下两个方向,调整好姿势就可以了。最开始在队列的处理上不太恰当TLE了几发(也可能是POJ的评测机炸了),后来调整了一下过掉了,注意输入字符时getchar
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;struct p{ int a, b, c;}q[1000010];int ans[1000010];int x[6] = {1, -1, 0, 0, 0, 0};int y[6] = {0, 0, 0, 0, -1, 1};int z[6] = {0, 0, -1, 1, 0, 0};bool vis[40][40][40];char map[40][40][40];int area, r, l, sx, sy, sz;int bfs(){ int rear, front, dx, dy, dz; memset(vis, false, sizeof(vis)); memset(ans, 0, sizeof(ans)); q[0].a = sx, q[0].b = sy, q[0].c = sz; front = rear = 0; while(front <= rear){ for(int i = 0; i < 6; i++){ dx = q[front].a + x[i]; dy = q[front].b + y[i]; dz = q[front].c + z[i]; if(!vis[dx][dy][dz] && (map[dx][dy][dz] == '.' || map[dx][dy][dz] == 'E') && dx >= 0 && dx < area && dy >= 0 && dy < r && dz >= 0 && dz < l){ vis[dx][dy][dz] = true; q[++rear].a = dx; q[rear].b = dy; q[rear].c = dz; ans[rear] = ans[front] + 1; if(map[dx][dy][dz] == 'E') return ans[rear]; } } front++; } return 0;}int main(){ //freopen("in.txt", "r", stdin); while(~scanf("%d%d%d", &area, &r, &l)){ //getchar(); if(area == 0 && r == 0 && l == 0) break; for(int k = 0; k < area; k++){ if(k) getchar(); for(int i = 0; i < r; i++){ getchar(); for(int j = 0; j < l; j++){ scanf("%c", &map[k][i][j]); if(map[k][i][j] == 'S') sx = k, sy = i, sz = j; } } //getchar(); } int cnt = bfs(); // cout<<cnt<<endl; if(cnt) printf("Escaped in %d minute(s).\n", cnt); else printf("Trapped!\n"); } return 0;}
0 0
- POJ 2251.Dungeon Master(BFS)
- poj Dungeon Master(Bfs)
- POJ 2251 Dungeon Master (三维BFS)
- poj-2251-Dungeon Master(bfs)
- poj 2251 Dungeon Master(BFS)
- poj 2251 Dungeon Master(bfs)
- POJ 2251 Dungeon Master(三维BFS)
- POJ 2251-Dungeon Master(BFS)
- POJ 2251 Dungeon Master (BFS)
- POJ 2251 Dungeon Master(BFS)
- POJ 2251 Dungeon Master(bfs)
- POJ - 2251 - Dungeon Master (简单BFS)
- POJ 2251 Dungeon Master (BFS)
- poj 2251 Dungeon Master(BFS)
- POJ 2251 Dungeon Master(BFS)
- 【POJ】-2251-Dungeon Master(BFS+队列)
- POJ 2251 - Dungeon Master(BFS)
- poj 2251 Dungeon Master(BFS)
- Java——用户界面的布局
- BAYKEE app开发中遇到的一些问题和解决办法
- 用 Redis 实现分布式锁
- poj2479 Maximum sum
- BestCoder Round #65 HDU 5593 ZYB's Tree (树形DP)
- POJ 2251.Dungeon Master(BFS)
- javascript权威指南学习笔记-函数闭包(十)
- Java-----两个日期之间相差天数和相隔天数
- ISS 网站发布没数据解决
- java多线程存钱,取钱例子
- Windows(MFC)消息映射
- (解题报告)HDU2007---平方和与立方和
- UVALive 6925Volume of Revolution(数学题)
- Windows系统下安装Node.js(2)