POJ 3984迷宫问题(BFS)
来源:互联网 发布:cst仿真软件破解版 编辑:程序博客网 时间:2024/06/06 06:41
简单深搜
#include<iostream>#include<cstdio>#include<algorithm>#include<cstdlib>#include<cmath>#include<string.h>#include<cstring>#include<string>#include<map>#include<set>#include<vector>#include<ctime>#include<queue>#define hash hashhusing namespace std;typedef long long ll;#define sp system("pause")#define PB push_backint G[5][5];int vis[5][5];int dx[4] = { 0, 0, 1, -1 };int dy[4] = { 1, -1, 0, 0 };class node{public:int now;int x, y;int px[26];int py[26];};int main(){memset(vis, 0, sizeof vis);memset(G, 0, sizeof G);for (int i = 0; i < 5; i++){for (int j = 0; j < 5; j++)scanf("%d", &G[i][j]);}node start;start.now = 0;start.x = 0;start.y = 0;start.px[start.now] = 0;start.py[start.now] = 0;queue<node>q;q.push(start);vis[0][0] = 1;while (!q.empty()){node t = q.front();if (t.x == 4 && t.y == 4){for (int i = 0; i <= t.now; i++){printf("(%d, %d)\n", t.px[i], t.py[i]);}sp;return 0;}q.pop();for (int i = 0; i < 4; i++){int a = t.x + dx[i];int b = t.y + dy[i];if (a >= 0 && a< 5 && b>= 0 &&b < 5&&!vis[a][b]&&!G[a][b]){vis[a][b] = 1;node in;in.now = t.now + 1;in.x = t.x + dx[i];in.y = dy[i] + t.y;memcpy(in.px, t.px, sizeof t.px); memcpy(in.py, t.py, sizeof t.py);in.px[in.now] = in.x;in.py[in.now] = in.y;q.push(in);}}}return 0;}
0 0
- POJ 3984-迷宫问题 BFS
- poj 3984 迷宫问题(bfs)
- POJ 3984 迷宫问题 BFS
- poj 3984 迷宫问题 bfs
- POJ 3984 || 迷宫问题 (bfs
- POJ 3984 迷宫问题 BFS
- POJ 3984 迷宫问题(bfs)
- BFS-POJ-3984-迷宫问题
- 迷宫问题 POJ 3984 【BFS】
- POJ 3984 迷宫问题 (BFS)
- POJ 3984:迷宫问题【BFS】
- POJ 3984迷宫问题(BFS)
- poj 3984 迷宫问题 bfs
- POJ 3984:迷宫问题【BFS】
- POJ 3984 迷宫问题 BFS
- poj 3984 迷宫问题(bfs)
- POJ 3984 ,迷宫问题(bfs)
- poj 3984 迷宫问题 (BFS)
- s标签不要嵌套s标签
- CentOS 7 yum安装路径查询方法
- Hibernate标识符属性(主键)生成策略全析
- 九度题目1087约数的个数
- 第4周项目2-太乐了
- POJ 3984迷宫问题(BFS)
- Contiki源码阅读之节点Rime地址
- 基于percona-monitoring-plugins实现Zabbix的MySQL多端口自动发现监控
- Mybatis(八)-一动态SQL
- Cookie and Session
- s标签不要嵌套s标签
- Linux 线程实现机制分析
- php正则表达式深入
- 获取系统联系人信息