救救我!
查看原帖
救救我!
924502
qianhaoyu楼主2023/10/22 20:18

为什么提交后3个RE,下载数据后正常输出

#include <bits/stdc++.h>
using namespace std;
struct node{
	int x,y,c;
};
queue<node>arr;
int bj[25][25];
int xx[13]={0,-2,-1,1,2,2,2,2,1,-1,-2,2,-2};
int yy[13]={0,2,2,2,2,1,-1,-2,-2,-2,-2,1,-1};
int bfs(int x,int y){
	bj[x][y]=1;
	arr.push({x,y,0});
	while(true){
		for(int i=1;i<=12;i++){
			if(arr.front().x+xx[i]>=1&&arr.front().y+yy[i]>=1&&bj[arr.front().x+xx[i]][arr.front().y+yy[i]]==0){
				arr.push({arr.front().x+xx[i],arr.front().y+yy[i],arr.front().c+1});
				bj[arr.front().x+xx[i]][arr.front().y+yy[i]]=1;
//				cout<<arr.back().x<<" "<<arr.back().y<<" "<<arr.back().c<<endl;
			}
			if(arr.back().x==1&&arr.back().y==1){
				return arr.back().c;
			}
		}
//		cout<<endl;
		arr.pop();
	}
}
int main(){
	int x,y;
	for(int I=1;I<=2;I++){
		memset(bj,0,sizeof(bj));
		while(!arr.empty())arr.pop();
		cin>>x>>y;
		cout<<bfs(x,y)<<endl;
	}
	return 0;
}
2023/10/22 20:18
加载中...