ARTI001 @ 2024-01-04 12:07:04
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstdlib>
using namespace std;
int n;
int map[1005][1005];
char a[1005][1005];
int x11,y11,x22,y22;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
bool vis[1005][1005];
struct node
{
int x,y,count;
}fir;
queue <node>q;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
map[i][j]=a[i][j]-'0';
}
}
cin>>x11>>y11>>x22>>y22;
fir.x=x11;
fir.y=y11;
vis[x11][y11]=1;
fir.count=0;
q.push(fir);
struct node top;
while(q.empty()==0)
{
top=q.front();//cout<<top.x<<" "<<top.y<<endl;
q.pop();
if(top.x==x22&&top.y==y22)goto what;
for(int i=0;i<4;i++)
{
struct node nxt;
nxt.x=top.x+dx[i];
nxt.y=top.y+dy[i];
if(nxt.x<1||nxt.x>n||nxt.y<1||nxt.y>n) continue;
if(map[nxt.x][nxt.y]==1)continue;
if(vis[nxt.x][nxt.y]==1)continue;
nxt.count=top.count+1;
vis[top.x][top.y]=1;
q.push(nxt);
}
}
what:
cout<<top.count;
return 0;
}
by ARTI001 @ 2024-01-13 10:49:39
标记的那个vis[nxt.x][nxt.y]=1打成vis[top.x][top.y]=1了:( 已经没事啦 希望大家少犯我这样的错误:)