POJ 2251 Dungeon Master 三维BFS
来源:互联网 发布:天刀少女最美捏脸数据 编辑:程序博客网 时间:2024/04/29 17:16
注意x,y,z的方向,简单的BFS
#include <algorithm>#include <iostream>#include <stdio.h>#include <queue>#include <string.h>using namespace std;struct node{ int x, y, z; int step;};int x,y,z,sx,sy,sz,ex,ey,ez;char map[40][40][40];int book[40][40][40];int dx[] = {1,-1,0,0,0,0};int dy[] = {0,0,1,-1,0,0};int dz[] = {0,0,0,0,1,-1};int check(node a){ if(a.x>=0&&a.x<x&&a.y>=0&&a.y<y&&a.z>=0&&a.z<z&&!book[a.x][a.y][a.z]&&map[a.x][a.y][a.z]!='#') return 1; else return 0;}int BFS(){ queue<node>Q; node a, next,q; a.x = sx; a.y = sy; a.z = sz; book[sx][sy][sz] = 1; a.step = 0; Q.push(a); while(!Q.empty()){ q = Q.front(); Q.pop(); if(q.x==ex&&q.y==ey&&q.z==ez){ return q.step; } for(int i = 0;i < 6;i++){ next.x = q.x+dx[i]; next.y = q.y+dy[i]; next.z = q.z+dz[i]; if(check(next)){ book[next.x][next.y][next.z] = 1; next.step = q.step+1; Q.push(next); } } } return -1;}int main(){ while(~scanf("%d %d %d", &x, &y, &z)){ if(x==0&&y==0&&z==0) break; for(int i = 0;i < x;i++){ for(int j = 0;j < y;j++){ scanf("%s", map[i][j]); for(int k = 0;k < z;k++){ if(map[i][j][k] == 'S'){ sx = i; sy = j; sz = k; }else if(map[i][j][k] == 'E'){ ex = i; ey = j; ez = k; } } } } memset(book,0,sizeof(book)); int t = BFS(); if(t == -1){ printf("Trapped!\n"); }else { printf("Escaped in %d minute(s).\n", t); } } return 0;}
0 0
- 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)
- <三维BFS搜索> POJ 2251 Dungeon Master
- 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(WA)Dungeon Master(三维BFS)
- POJ.2251 Dungeon Master (三维BFS)
- poj 2251Dungeon Master(三维bfs)
- 深入理解Objective-C:Category
- HDOJ-----1155Bungee Jumping物理题
- Python学习笔记(1)
- centos7.2上安装chrome
- UVA 10200 Prime Tim
- POJ 2251 Dungeon Master 三维BFS
- zabbix 汉化
- 欢迎使用CSDN-markdown编辑器
- C语言中的extern,static和register的一些用法
- java设计模式——享元模式(Flyweight Pattern)
- C语言中内存分配
- java基础(二)
- HDU2186--水
- 素数打表 UVA 10200 - Prime Time