poj 3984 bfs
来源:互联网 发布:淘宝上新怎么抢的快 编辑:程序博客网 时间:2024/04/28 07:18
http://poj.org/problem?id=3984
#include<iostream>#include<stdio.h>#include<cstring>#define Max 0x7f7f7f7fusing namespace std;int map[6][6];int visited[6][6];int dir[4][2]={{1,0},{-1,0},{0,-1},{0,1}};int ans[6][6];int pre[30];struct node{ int x; int y;};node path[30];void output(int head){ int tmp=pre[head]; if(tmp==0) printf("(%d, %d)\n",path[tmp].x,path[tmp].y); else output(tmp); printf("(%d, %d)\n",path[head].x,path[head].y);}void bfs(){ memset(visited,0,sizeof(visited)); memset(ans,Max,sizeof(ans)); int head=0; int tail=1; pre[head]=-1; path[head].x=0; path[head].y=0; visited[path[head].x][path[head].y]=1; while(head<tail) { int x=path[head].x; int y=path[head].y; if(x==4 && y==4) { output(head); return ; } for(int i=0;i<4;i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(visited[xx][yy]==0 && xx>=0 && xx<5 && yy>=0 && yy<5 && map[xx][yy]!=1) { path[tail].x=xx; path[tail].y=yy; pre[tail]=head; tail++; visited[xx][yy]=1; } } head++; }}int main(){ int i,j; for(i=0;i<5;i++) for(j=0;j<5;j++) scanf("%d",&map[i][j]); bfs(); return 0;}
- 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)
- BFS-POJ-3984-迷宫问题
- 迷宫问题 POJ 3984 【BFS】
- POJ 3984 迷宫问题 (BFS)
- zoj 1586 prim
- codeforces 334A
- zoj 2158 prim
- 精通软件性能测试与LoadRunner最佳实战 连载十一
- 最小生成树-prim算法模板
- poj 3984 bfs
- git错误解决
- 【ubuntu】使用ubuntu过程中的入门
- Ubuntu12.04下安装eclipse C/C++开发环境
- dvm与jvm的区别
- C++程序员必看书单
- HTTP 协议详解
- PHP中的ob_start用法详解
- operator new,new operator和placement new的使用