kqing @ 2018-12-27 22:30:28
using namespace std;
int const maxn=10000;
int n,num;
int b,e;
int c[maxn];
char ju[maxn][maxn];
int a[maxn*maxn][3];
int dx[5]={0,0,-1,0,1};
int dy[5]={0,-1,0,1,0};
void init()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
cin>>ju[i][j];
}
}
void bfs(int x,int y)
{
int num=0;
int head, tail;
a[1][1]=x;
a[1][2]=y;
head=0;
tail=1;
do
{
head++;num++;
for(int i=1;i<=4;i++)
{
int x3,y3;
x3=a[head][1]+dx[i];
y3=a[head][2]+dy[i];
if(ju[x3]
[y3]=='0'&&x3>0&&x3<=n&&y3>0&&y3<=n)
{
tail++;
a[tail][1]=x3;
a[tail][2]=y3;
ju[x3][y3]=1;
};
if(a[tail][1]==b&&a[tail][2]==2)
{
c[num]=1;
}
}
} while(head<tail);
}
int main()
{
int x1,x2,y1,y2;
init();
cin>>x1>>y1>>x2>>y2;
b=x2;
e=y2;
bfs(x1,y1);
for(int i=1;i<=maxn;i++)
{
if(c[i]==1)
{
cout<<i<<endl;
break;
}
} return 0; }
by 初音Miku @ 2018-12-27 22:34:43
你这Markdown看得我眼花缭乱
by memset0 @ 2018-12-27 23:03:12
希望更丰富的展现?使用Markdown
by pipiispig @ 2018-12-27 23:03:27
希望更丰富的展现?使用Markdown
by kqing @ 2018-12-28 23:21:39
{
{
} }
{
{
{
[y3]=='0'&&x3>0&&x3<=n&&y3>0&&y3<=n) {
};
{
} }
}
{
{
{
}