POJ 3626 Mud Puddles (BFS)
来源:互联网 发布:个性化推荐算法 编辑:程序博客网 时间:2024/05/21 19:08
点击打开链接
将所有的数据都+500,然后模版。。
#include"stdio.h"#include"string.h"#include"queue"using namespace std;int d[4][2]={1,0,0,1,-1,0,0,-1};int x,y,n,map[1001][1001];struct node{int x,y,step;};void bfs(){int i;queue<node>Q;node q,p;p.x=500;p.y=500;p.step=0;Q.push(p);map[p.x][p.y]=1;while(!Q.empty()){p=Q.front();Q.pop();for(i=0;i<4;i++){q.x=p.x+d[i][0];q.y=p.y+d[i][1];q.step=p.step+1;if(q.x>=0&&q.x<=1000&&q.y>=0&&q.y<=1000&&map[q.x][q.y]==0){if(q.x==x&&q.y==y){printf("%d\n",q.step);return ;}map[q.x][q.y]=1;Q.push(q);}}}}int main(){int i,a,b;while(scanf("%d%d%d",&x,&y,&n)!=-1){x+=500;y+=500;memset(map,0,sizeof(map));for(i=0;i<n;i++){scanf("%d%d",&a,&b);map[a+500][b+500]=1;}if(x==500&&y==500)printf("0\n");else bfs();}return 0;}
- POJ 3626 Mud Puddles (BFS)
- POJ 3626 Mud Puddles(bfs)
- POJ 3626 Mud Puddles(BFS)【模板】
- POJ 3626 Mud Puddles(超简单BFS)
- poj 3626 Mud Puddles (简单BFS)
- POJ 3626 Mud Puddles
- POJ 3626 Mud Puddles 练习 BFS 宽度优先搜索
- USACO 2007 Dec Silver Mud Puddles bfs or A-star
- poj3626 Mud Puddles
- poj 3626 简单bfs
- Poj 3626 BFS
- POJ 3626 BFS
- POJ-2056(BFS)
- POJ-1198(BFS)
- POJ 3984(bfs)
- POJ 3278(BFS)
- POJ 3126 (BFS)
- POJ 3414 (BFS)
- 获取进程命令行参数
- TCP状态迁移,CLOSE_WAIT & FIN_WAIT2 的问题
- 活用注册表让Windows CE如虎添翼
- 非迅雷会员免费看云点播方法,无需软件享官方云点播
- sequencefile处理小文件实例
- POJ 3626 Mud Puddles (BFS)
- 没落的delphi的日志类log4delphi
- zoj1115-----------Digital Roots
- Windows Linux 删除N天之前的文件脚本
- Unity 牛人到处有啊。。。。。
- hdu 1548 A strange lift (bfs)
- SecureCRT连接虚拟机下的Ubuntu
- BK-Tree
- 今天要实现在winform中使用时间控件