Virtual Judge POJ 2251 Dungeon Master
三维数组加宽搜 #include <stdlib.h> #include <string.h> #include <stdio.h> const int MAXN=50; int c, k, h; char ma[MAXN][MAXN][MAXN]; //定义三维数组 长宽高 int visit[MAXN][MAXN][MAXN]; //标记数组 struct node { int c, k, h;//结构体记录到达某个点 c长k宽h高 int step;//走的步数 }; struct node t[33433];//结构体队列 struct node p, q, w, l; int f[][3] = {0,0,1, 0,0,-1, 0,1,0, 0,-1,0, 1,0,0, -1,0,0};//向上下左右前后六个方向移动 包括上楼 void bfs() { visit[p.c][p.k][p.h] = 1;//标记已经走过 int front = 0, rear = 0; t[rear++] = p;//入队 while(front!=rear) { //当队列不为空的时候 w = t[front++]; if(w.c==q.c&&w.k==q.k&&w.h==q.h) { //如果是终点,直接输出 printf("Escaped in %d minute(s).\n", w