我的RE什么情况
查看原帖
我的RE什么情况
690243
houluyu楼主2022/10/10 19:09

只有60分

#include<iostream>
#include<cstdio>
using namespace std;
int n,stx,sty,enx,eny;
bool map_[10005][10005];
bool used[10005][10005];
long long x[400005],y[400005],z[400005];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
char ch;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>ch;
			if(ch=='1')map_[i][j]=1;
			else map_[i][j]=0;
		}
	}
	cin>>stx>>sty>>enx>>eny;
	int head=1,tail=1;
	x[head]=stx,y[head]=sty,z[head]=0;
	used[stx][sty]=1;
	while(head<=tail)
	{
		if(x[head]==enx&&y[head]==eny)
		{
			printf("%d\n",z[head]);
		//	break;
			return 0;
		 } 
		for(int i=0;i<4;i++)
		{
			int tx=x[head]+dx[i];
			int ty=y[head]+dy[i];
			if(tx>0&&tx<=n&&ty>0&&ty<=n&&!used[tx][ty]&&!map_[tx][ty])
			{
				used[tx][ty]=1;
				x[++tail]=tx;
				y[tail]=ty;
				z[tail]=z[head]+1; 
			}
		}
		head++; 
	}
	return 0;
}
2022/10/10 19:09
加载中...