FCB_1899 @ 2021-02-26 09:46:24
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
bool gone[1001][1001]={0};
bool street[1001][1001];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
struct node
{
int x,y;
int step;
};
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
for(int j=1;j<=n;j++)
street[i][j]=s[j-1]-'0';
}
int sx,ex,sy,ey;
cin>>sx>>sy>>ex>>ey;
if(street[sx][sy]==1||street[ex][ey]==1) return 0;
queue<node> q;
node u;
u.x=u.y=1;
u.step=0;
q.push(u);
gone[1][1]=1;
while(!q.empty())
{
node t=q.front();q.pop();
if(t.x==n&&t.y==n) {cout<<t.step; return 0;}
for(int i=0;i<4;i++)
{
int nx=t.x+dx[i],ny=t.y+dy[i];
if(gone[nx][ny]==0&&street[nx][ny]==0&&nx>0&&nx<=n&&ny>0&&ny<=n)
{
gone[nx][ny]=1;
node p;
p.x=nx;p.y=ny;p.step=t.step+1;
q.push(p);
}
}
}
return 0;
}
by FCB_1899 @ 2021-02-26 09:53:25
求助!
by 王熙文 @ 2021-02-26 10:04:42
@liuxingjian u.x=u.y=1;
应该是起点吧,输入的
by AuCloud @ 2021-02-26 10:09:36
楼上正解
by FCB_1899 @ 2021-02-26 10:10:52
@王熙文 @AuCloud 谢谢,AC了,顺便 %%%stO wxw