本地测试测试点1正确,但是全wa
查看原帖
本地测试测试点1正确,但是全wa
723431
sunyufei2005楼主2022/9/13 16:20
#include<bits/stdc++.h>
using namespace std;
int dx[]={1,2,2,2,2,1,-1,-2,-2,-2,-2,-1};
int dy[]={2,2,1,-1,-2,-2,-2,-2,-1,1,2,2};
bool v[1000][1000];
struct point{
	int x,y,step;
};
void bfs(int x,int y){
	point a;
	memset(v,0,sizeof v);
	a.x=x,a.y=y;
	v[x][y]=1;
	queue<point>q;
	q.push(a);
	while(q.size())
	{
		point b=q.front();
		q.pop();
		for(int i=0;i<12;i++)
		{
			int xx=b.x+dx[i];
			int yy=b.y+dy[i];
			point c;
			c.x=xx,c.y=yy;c.step=b.step+1;
			if(xx<=0||xx>22||yy<=0||yy>22)continue;
			if(xx==1&&yy==1)
			{
				cout<<c.step<<endl;
				return ;
			}
			if(!v[xx][yy])
			{
				q.push(c);
				v[xx][yy]=1;
			}
		}
		
	}
}
int main(){
    int x1,yy1,x2,yy2;
	cin>>x1>>yy1>>x2>>yy2;
	bfs(x1,yy1);
	bfs(x2,yy2);
}
2022/9/13 16:20
加载中...