poj3984迷宫问题
来源:互联网 发布:悠唐网络是真的吗 编辑:程序博客网 时间:2024/05/29 14:24
#include<iostream>#include<queue>#include<cstdio>using namespace std;int go[4][2] = { { -1,0 },{ 1,0 },{ 0,1 },{ 0,-1 } };bool visit[35];int pre[35];int map[6][6];void print(int val){if (val < 25 && val >= 0 && pre[val] != -1){print(pre[val]);cout <<'('<< val / 5 << ", " << val % 5 <<')'<< endl;}elsecout <<'('<< 0 << ", " << 0<<')' << endl;}void BFS(){pre[0] = -1;visit[0] = true;queue<int> q;q.push(0);while (!q.empty()){int n = q.front();q.pop();int c = n % 5;int r = n / 5;for (int i = 0; i < 4; ++i){int nowc = c + go[i][0];int nowr = r + go[i][1];int tem = nowc + nowr * 5;if (nowc>=0&& nowc<5&& nowr >=0&&nowr<5 && !visit[tem]&& !map[r + go[i][1]][c + go[i][0]]){pre[nowc+nowr*5] = n;visit[nowc+nowr*5] = true;if (nowc+nowr*5 == 24){print(24);}q.push(tem);}}}}int main(){ for (int i = 0; i <5; i++)for (int j = 0; j < 5; j++){cin >> map[i][j];visit[i * 5 + j] = false;}BFS();//system("pause");}
广搜问题,每个地点只能到达一次,只有一个前驱,故可以根据正着广搜以表示所有点的前驱,再递归输出
0 0
- POJ3984 迷宫问题 BFS
- POJ3984 迷宫问题
- HUD--POJ3984 迷宫问题
- POJ3984 迷宫问题 BFS
- poj3984 迷宫问题
- poj3984(迷宫问题)
- poj3984 迷宫问题
- [POJ3984]迷宫问题
- poj3984 迷宫问题(BFS)
- POJ3984 迷宫问题
- POJ3984 迷宫问题【BFS】
- poj3984 迷宫问题
- Poj3984- dfs -迷宫问题
- poj3984迷宫问题(bfs)
- poj3984迷宫问题
- poj3984 迷宫问题
- poj3984迷宫问题
- POJ3984 迷宫问题【BFS】
- Android第五周的学习笔记
- pods安装
- python 出现错误 SyntaxError: Non-ASCII character 的解决方法
- Leetcode #27. Remove Element 移除元素 解题报告
- JavaScript Math.floor()
- poj3984迷宫问题
- 设计模式学习笔记——桥接模式
- Scanner类的使用
- Java >>> 详解
- MySQL性能分析
- 1-1-JS中的HTML属性操作
- AOJ 0118 Property Distribution(dfs 求连通块)
- 并发学习笔记(二):synchronized代码块
- 浪漫的表白 。刚接触编程语言 ,一个学长做的题。其实很简单,就是找规律输出,只是觉得输出特别浪漫,所以在此作为我人生第一个博客文章!!哈哈,大神之路 走起