题目:
#include<cstdio>
#include<cstring>
#include<queue>
#include<iomanip>
using namespace std;
const int N=501;
int a[N][N];//定义501*501的储存答案的数组
struct point{
int x;
int y;
int t;
};//广搜结构体,对于每一个点,要储存它的横坐标(x坐标),纵坐标(y坐标),当前所走的步数
queue<point> que;//广搜必备队列,C++STL万岁O(∩_∩)O~~
int n,m,sx,sy;//棋盘边界、出发点坐标。
int dx[8]={-2,-2,-1,-1,2,2,1,1};
int dy[8]={1,-1,2,-2,1,-1,2,-2};//坐标偏移量
int main()
{
memset(a,-1,sizeof(a));//答案数组全部赋值-1,能达到就改为当前步数,不能改就直接输出。
scanf("%d%d%d%d",&n,&m,&sx,&sy);
a[sx][sy]=0;//切记,一定要把起点赋值为0,否则全WA
//广搜
que.push((point){sx,sy,0});//将起点放入队列
while(!que.empty())//只要还有可以走的点,就继续执行
{
point f=que.front();//将当前点