7.26
POJ迷宫问题
note:一开始不懂怎么把路径输出来,查了很久,有用dfs的,看上去很复杂,最后终于找到用栈输出并且和我习惯很像的代码。巧妙之处是用一个结构体数组储存路径的节点,结构体又包含上一个节点的坐标
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<malloc.h>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
struct Node
{
int x, y, step, prex, prey; //上一层的x和y
};
Node path[5][5];//记录第一次到坐标x, y 的节点
int map[5][5];//地图
int vis[5][5];//该点是否查询过
int move[4][2] = {
0,1, 0,-1, 1,0, -1,0};
bool check(int x, int y)
{
return x >= 0 && x < 5 && y >= 0 && y < 5 && !map[x][y] && !vis[x][y];
}
void findpath(int ex,