poj 1915 Knight Moves bfs 用move数组计算第几步好使
来源:互联网 发布:tv007网络电视下载 编辑:程序博客网 时间:2024/05/16 08:00
#include<iostream>
using namespace std;
#include<queue>
int a1,b1,a2,b2;
int size;
int move[305][305];
int dir[8][2]={-2,-1,-2,1,-1,2,1,2,2,1,2,-1,1,-2,-1,-2};
void bfs(int x,int y)
{
queue<int> q;
q.push(x);
q.push(y);
while(!q.empty())
{
int m=q.front();q.pop();
int n=q.front();q.pop();
if(m==a2 && n==b2)
break;
for(int i=0;i<8;i++)
{
int mm=m+dir[i][0];
int nn=n+dir[i][1];
if(mm<0||mm>=size||nn<0||nn>=size)
continue;
if(!move[mm][nn])
{
move[mm][nn]=move[m][n]+1;
q.push(mm);
q.push(nn);
}
}
}
}
int main()
{
int x;
cin>>x;
while(x--)
{
cin>>size;
cin>>a1>>b1;
cin>>a2>>b2;
memset(move,0,sizeof(move));
bfs(a1,b1);
cout<<move[a2][b2]<<endl;
}
return 0;
}
- poj 1915 Knight Moves bfs 用move数组计算第几步好使
- POJ 1915 Knight Moves bfs
- POJ 1915Knight Moves(BFS)
- poj 1915 Knight Moves(bfs)
- poj 1915 Knight Moves(bfs)
- POJ 1915 BFS-Knight Moves
- [BFS]poj 1915 Knight Moves
- Poj 1915 Knight Moves ( BFS
- POJ 1915 Knight Moves BFS
- 【BFS】poj 1915 Knight Moves
- POJ 1915 Knight Moves bfs || 双向bfs
- poj 1915 knight moves(bfs 简单)
- poj 1915 knight moves (双向bfs)
- POJ 1915 Knight Moves (BFS)
- poj 1915 Knight Moves(BFS遍历)
- Poj 1915 Knight Moves(BFS)
- POJ 1915 Knight Moves(双向BFS)
- POJ 1915 Knight Moves(DFS/BFS)
- 详解Struts中Validator验证框架的使用
- Looper,Handler,Message,MessageQueue
- unicode转换
- MediaPlayer,Camera
- Redhat 下通过 Webmin 配置 Samba 的问题
- poj 1915 Knight Moves bfs 用move数组计算第几步好使
- 关于 MS SQL 触发器 的一些用法
- ksoap2 传webservice byte[]
- JQuery是什么?
- 贪心法实现Prim最小生成树(java)
- Http 上传文件之multipart form-data
- 赤脚追回曾经失去的……
- Aio.exe用法
- 理解HTTP session原理及应用