尚在调试中。。。。。
#include <cstdio>
struct note
{
int x;
int y;
int s;
};
int main()
{
struct note que[2501];
int a[51][51]={0},book[51][51]={0};
int next[4][2]={{ 0, 1},
{ 1, 0},
{ 0,-1},
{-1, 0}};
int top,bottom;
int i,j,k,n,m,x1,y1,x2,y2,tx,ty,flag;
scanf("%d",&n);
getchar();
for(i=1;i<=n;i++)
{
j=1;
while(a[i][j]=getchar() && a[i][j]!='\n')
{
if(a[i][j]=='1')
a[i][j]=1;
else
a[i][j]=0;
j++;
}
m=j;
}
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
top=1;
bottom=0;
bottom++;
que[bottom].x=x1;
que[bottom].y=y1;
que[bottom].f=0;
que[bottom].s=0;
flag=0;
while(top<=bottom)
{
for(k=0;k<=3;k++)
{
tx=que[top].x+next[k][0];
ty=que[top].y+next[k][1];
if(tx<1 || tx>n || ty<1 || ty>m)
continue;
if(a[tx][ty]==0 && book[tx][ty]==0)
{
book[tx][ty]=1;
bottom++;
que[bottom].x=tx;
que[bottom].y=ty;
que[bottom].f=top;
que[bottom].s=que[top].s+1;
}
if(tx==x2 && ty==y2)
{
flag=1;
break;
}
}
if(flag==1)
break;
top++;
}
printf("%d",que[bottom].s);
getchar();
getchar();
return 0;
}