有没有佬帮我看看为什么会MLE?用的BFS
查看原帖
有没有佬帮我看看为什么会MLE?用的BFS
1257536
S1417830194楼主2024/3/10 21:54
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

int m,n,x,y,Board[401][401];
bool intCome[401][401]={0};
int X[8]={1,-1,2,-2,2,1,-1,-2};
int Y[8]={2,-2,-1,1,1,-2,2,-1};

struct Node
{
	int x,y;
	int steps;
}p,top,newNode;

queue<Node> q;
int main()
{

	cin>>n>>m>>x>>y;
	p.x=x-1;p.y=y-1;p.steps=0;
	q.push(p);
	
	memset(intCome,false,sizeof(intCome));
	memset(Board,-1,sizeof(Board));
	
	**while(!q.empty())
	{
		top=q.front();
		q.pop();
		
		Board[top.x][top.y]=top.steps;
		intCome[top.x][top.y]=true;			
			
		for(int i=0;i<8;i++)
		{
			if(top.x+X[i]>=0 && top.x+X[i]<n && top.y+Y[i]>=0 && top.y+Y[i]<m && intCome[top.x+X[i]][top.y+Y[i]]==false ) 
			{
				newNode.x=top.x+X[i]; newNode.y=top.y+Y[i]; newNode.steps=top.steps+1;
				q.push(newNode);
			}
		}
	}**

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(j==m-1) 
				cout<<Board[i][j]<<endl;
			else
				cout<<Board[i][j]<<" ";
		}
	}
		
	return 0;
} 
2024/3/10 21:54
加载中...