poj-3084 输出路径的BFS
来源:互联网 发布:化学化工物性数据手册 编辑:程序博客网 时间:2024/04/29 19:16
http://poj.org/problem?id=3984
#include<stdio.h> #include<iostream> #include<math.h> #include<stdlib.h> #include<ctype.h> #include<algorithm> #include<vector> #include<string.h> #include<queue> #include<stack> #include<set> #include<map> #include<sstream> #include<time.h> #include<utility> #include<malloc.h> #include<stdexcept> #include<iomanip> #include<iterator> using namespace std;int n, m;int p[35][35];int vis[6][6];int dir[4][2] = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } };struct node{int x;int y;};struct node pre[30][30];//存储节点前一个位置int check(int x, int y){if (x >= 0 && x < 5 && y >= 0 && y < 5)return 1;return 0;}void printf_path(){stack<node> path;//栈用来保存路径node ss;ss.x = 4;ss.y = 4;while (1){path.push(ss);if (!ss.x && !ss.y)break;ss = pre[ss.x][ss.y];}while (!path.empty()){ss = path.top();path.pop();printf("(%d, %d)\n",ss.x,ss.y);}}void bfs(){memset(vis,0,sizeof(vis));queue <node> q;node qq, qqq;qq.x = 0;qq.y = 0;vis[0][0] = 1;q.push(qq);while (!q.empty()){qq = q.front();q.pop();if (qq.x == 4 && qq.y == 4){printf_path();return;}for (int i = 0; i < 4;i++){int x = qq.x + dir[i][0];int y = qq.y + dir[i][1];if (!check(x,y) || vis[x][y] || p[x][y] == 1)continue;qqq = qq;qqq.x = x;qqq.y = y;pre[qqq.x][qqq.y] = qq;vis[x][y] = 1;q.push(qqq);}}return;}int main(){for (int i = 0; i < 5; i++){for (int j = 0; j < 5; j++){cin >> p[i][j];}}bfs();return 0;}
0 0
- poj-3084 输出路径的BFS
- POJ (BFS + 路径输出)
- poj 3984 迷宫问题(BFS+输出路径)
- POJ 1077 Eight(BFS:输出路径)
- poj 3984 迷宫问题 bfs输出路径
- poj 3984 迷宫问题【bfs+输出路径】
- poj 3984 迷宫问题(BFS+输出路径)
- poj 3984 (bfs+输出路径)
- POJ-3669的基础上输出逃生路径(bfs)(宽度优先搜索)
- BFS和DFS的路径输出
- POJ 3414 Pots(bfs + 判重 + 输出路径)
- POJ 1606 Jugs(BFS:找最短路径并输出)
- poj 3414 Pots(广搜BFS+路径输出)
- poj 1606 Jugs(广搜BFS+路径输出)
- K - 迷宫问题 POJ 3984 BFS路径输出
- POJ 3984:迷宫问题 bfs+递归输出路径
- POJ 3984 迷宫问题(BFS+路径输出)
- POJ - 3984 迷宫问题 (BFS+前缀处理输出路径)
- 两个字符串
- 腾讯内部产品课:细分用户画像
- Tomcat内存溢出,修改配置
- Mac使用操作
- Min Stack
- poj-3084 输出路径的BFS
- [Python]网络爬虫(12):爬虫框架Scrapy的第一个爬虫示例入门教程
- nyoj 求次数
- Android 签名问题总结
- Android异步加载图像小结 (含线程池,缓存方法)
- NDIS驱动结构
- android SlidingMenu相关介绍
- IName接口
- 一个4节点Hadoop集群的配置示例