poj3626
来源:互联网 发布:360 for mac官方下载 编辑:程序博客网 时间:2024/06/06 16:55
/*
分析:
基础广搜。
2012-07-30 09:46
*/
分析:
基础广搜。
2012-07-30 09:46
*/
#include"stdio.h"#include"string.h"#include"queue"using namespace std;int map[1011][1011];int flag[1011][1011];int s_x=500,s_y=500;int e_x,e_y;int dir[4][2]={1,0, -1,0, 0,1, 0,-1};struct node{int x,y;int step;};int judge(int x,int y){if(x<0 || y<0 || x>1000 || y>1000)return 1;if(map[x][y]==-1)return 1;if(flag[x][y])return 1;return 0;}int BFS(){queue<node>q;node cur,next;int i;cur.x=s_x;cur.y=s_y;cur.step=0;flag[cur.x][cur.y]=1;q.push(cur);while(!q.empty()){cur=q.front();q.pop();if(cur.x==e_x){if(cur.y==e_y)return cur.step;}for(i=0;i<4;i++){next.x=cur.x+dir[i][0];next.y=cur.y+dir[i][1];if(judge(next.x,next.y))continue;flag[next.x][next.y]=1;next.step=cur.step+1;q.push(next);}}return -1;}int main(){int a,b;int n;while(scanf("%d%d%d",&e_x,&e_y,&n)!=-1){e_x+=500;e_y+=500;memset(map,0,sizeof(map));memset(flag,0,sizeof(flag));while(n--){scanf("%d%d",&a,&b);a+=500;b+=500;map[a][b]=-1;}printf("%d\n",BFS());}return 0;}
- poj3626
- poj3626 Mud Puddles
- poj3626广搜
- 广搜 poj3626
- Qt中的垃圾收集机制
- 四种途径将HTML5应用变成android应用
- 基于ARM的嵌入式Linux移植真实体验(1)――基本概念
- MSM平台linux/android build笔记
- 用PendingIntent创建一个Alarm的基本过程
- poj3626
- PHP验证码类,简单安全的PHP验证码
- 体会setCapture和releaseCapture判断鼠标是否在某一区域
- CentOS下yum找不着可用的rpm的解决方法
- Google光纤试点堪萨斯城 1000M无敌网速!
- android获取string.xml的值
- 搞IT的到底怎么了
- JSP官方文档
- Node(10) File System, IO, Stream