POJ1915 BFS
来源:互联网 发布:oracle导入txt数据 编辑:程序博客网 时间:2024/05/22 17:50
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#include <iostream>#include <math.h>#include"queue"using namespace std;const int maxn=300;int l;int visit[maxn][maxn];int dir[8][2]={{-2,1},{-1,2},{2,1},{1,2},{-2,-1},{-1,-2},{2,-1},{1,-2}};struct point{int x,y,step;point(){x=y=step=0;}}Start,End;bool equal(point a,point b){return a.x==b.x&&a.y==b.y;}int bfs(){queue<point>dot;dot.push(Start);visit[Start.x][Start.y]=1;while(!dot.empty()){point next,cur;cur=dot.front();dot.pop();for(int i=0;i<8;i++){next.x=cur.x+dir[i][0];next.y=cur.y+dir[i][1];if(next.x>=0&&next.x<l&&next.y>=0&&next.y<l&&!visit[next.x][next.y]){if(equal(next,End)) return cur.step+1;visit[next.x][next.y]=1;next.step=cur.step+1;dot.push(next);}}}}int main(){int t;scanf("%d",&t);while(t--){memset(visit,0,sizeof(visit));scanf("%d",&l);scanf("%d%d%d%d",&Start.x,&Start.y,&End.x,&End.y);if(equal(Start,End)) {printf("%d\n",0);continue;}int ans=bfs();printf("%d\n",ans);}return 0;}
0 0
- poj1915 BFS
- poj1915 bfs
- POJ1915 BFS
- POJ1915 BFS&双向BFS
- POJ1915 经典bfs
- (未)poj1915(bfs)
- POJ1915:Knight Moves(BFS)
- poj1915 简单bfs
- POJ1915 (Knight Moves) BFS
- poj1915之BFS
- poj1915~双向bfs和bfs
- POJ1915 Knight Moves 经典BFS
- BFS广度优先搜索 poj1915
- poj1915 Knight Moves(bfs)
- poj1915 Knight Moves(bfs)
- poj1915--Knight Moves(初级BFS)
- POJ1915(Knight Moves,双向BFS)
- POJ1915
- VirtualBox kernel driver not installed 解决办法
- CRC32学习总结
- 图的深度优先搜索(Depth First Search,DFS)
- [1.1] 面向对象编程之get-set方法与构造器详解
- webservice基础
- POJ1915 BFS
- linphone-CallManager.java文件分析
- 深入解析淘宝Diamond之客户端架构
- 图片边框
- final修饰符
- 树莓派 Learning 002 装机后的必要操作 --- 06 共用键鼠 之 windows和树莓派
- String的==和equals()
- 【数组14】构建乘积数组
- HDU-5326 Work