#include<bits/stdc++.h>///该头文件为万能头文件,有些学校oj不能使用,读者可根据需要自行修改
using namespace std;
const int MAXN=;
int vis[MAXN][MAXN];
int X[]={,-,-,-,-,,,,};
int Y[]={,-,-,,,,,-,-};
struct point
{
int x;
int y,step;
};
queue<point>q; int xx1,yy1,x2,y2;
int res;
void bfs()
{
vis[xx1][yy1]=;//
point a;
a.x=xx1;
a.y=yy1;
a.step=;
q.push(a);//
while(!q.empty())//
{
point head=q.front();//
q.pop();
if(head.x==x2&&head.y==y2)//
{
//若找到需要的点则结束循环并返回
res=head.step;
return;
} else
{ for(int i=;i<=;i++)//
{
point t;
t.x=head.x+X[i];
t.y=head.y+Y[i];
if(t.x>=&&t.x<=&&t.y>=&&t.y<=&&vis[t.x][t.y]==)///把八个方向都放到队列中去
{
vis[t.x][t.y]=;///每一步都等于其上一步+1
t.step=head.step+;
//printf("x=%d y=%d\n",t.x,t.y);
q.push(t);
}
}
}
}
}
int main()
{ while(~scanf("%d %d %d %d",&xx1,&yy1,&x2,&y2))
{
memset(vis,,sizeof(vis));
while(!q.empty())///清空队列
{
q.pop();
}
bfs();
printf("%d\n",res);
}
return ;
}

最新文章

  1. C#连接Access与SQL Server
  2. 当年只会C# 所以写C++就成这样了!
  3. 条件变量pthread_cond_t怎么用
  4. [译]Mongoose指南 - Schema
  5. Combination Sum II [LeetCode]
  6. NSLog说明
  7. .net概述1
  8. Divisor Summation_
  9. LaTeX的表格插入与排版
  10. lua table操作实例详解
  11. 一个基于H5audio标签的vue音乐播放器
  12. WinForm 绑定到嵌套对象上的属性
  13. hive复杂类型实战
  14. 二十一、Linux 进程与信号---进程资源限制
  15. Swagger2限定接口范围
  16. Mysql SQL优化系列之——执行计划连接方式浅释
  17. vue路由权限之访问权限(meta控制是否有访问权限)
  18. Eclipse CDT 插件列表
  19. es match、match_phrase、query_string和term的区别
  20. javaScript嵌入式环境Duktape的安装

热门文章

  1. Math &amp; Number Theory
  2. pillow的用法
  3. JS学习笔记Day9
  4. MySQL_列值为null对索引的影响_实践
  5. Maven 学习总结 (二) 之 生命周期与插件
  6. ArcGis Python脚本——根据接图表批量裁切分幅影像
  7. Karma (Test runner)
  8. DUMP3 企业级电商项目
  9. like 模糊查询
  10. Python3:几行代码实现阶乘