bfs模板
来源:互联网 发布:手机直播软件排名 编辑:程序博客网 时间:2024/06/11 06:07
#include<iostream>const int INF=1000000;typedef pair<int,int> P;char maze[MAX][MAX];int N,M;int sx,xy;int gx,gy;int d[MAX][MAX]; //the distance to every pointint dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};int bfs(){queue<P> que;for(int i=0;i<N;++i){ for(int j=0;j<M;++j){d[i][j]=INF; //initialize every point to INF}}que.push(P(sx,sy));d[sx][sy]=0;while(que.size()){P p=que.front();que.pop();if(p.first==gx&p.second==gy)break;for(int k=0;k<4;++k){int nx=p.first+dir[k][0];int ny=p.second+dir[k][1];if(0<=nx&&nx<N&&0<=ny&&ny<M&&maze[nx][ny]!='#'&&d[nx][ny]==INF){que.push(P(nx,ny));d[nx][ny]=d[p.first][p.second]+1;}}}return 0;}void solve(){int res=bfs();printf("%d",res);}
0 0
- 【模板】BFS
- bfs模板
- BFS模板
- 模板,BFS
- BFS模板
- BFS 模板
- BFS模板
- bfs模板
- bfs模板
- BFS 模板
- BFS模板
- BFS模板
- bfs模板
- bfs模板
- bfs模板
- BFS模板
- BFS 模板
- bfs模板
- 享元模式(flyweight)
- EXE文件的加载过程
- Problem I: 最大连续子段和问题
- LightOJ1009---Back to Underworld (bfs染色)
- Bonjour 服务
- bfs模板
- 攻克GRE数学中的图表题
- Liunx下解决svn: Cannot negotiate authentication mechanism错误问题
- eclipse中常用的快捷键
- 斗西游
- 简单题目的dfs模版
- HMM-前向后向算法
- Problem J: Home on the Range 家的范围
- 代码注释,神兽护体,代码无bug