求助啊~大佬

P1746 离开中山路

kqing @ 2018-12-29 00:44:41

include <bits/stdc++.h>

using namespace std;

char ju[1100][1100];

int dx[5]={0,0,-1,0,1},

dy[5]={0,-1,0,1,0},a[100000][3],b[1100];

int c,e,n;

int bfs(int x,int y)

{

a[1][1]=x;

 ### a[1][2]=y;
### int head,tail;

head=0;tail=1;
do{
    head++;
    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++;
        b[tail]=b[head]+1;
            a[tail][1]=x3;
            a[tail][2]=y3;
            ju[x3][y3]=1;};
        if(a[tail][1]==c&&a[tail][2]==e)
        {
            cout<<b[tail]<<endl;
        return 0;
        }
        }

}while (head<tail);

}

int main()

{

cin>>n;
int i,j,x1,y1,x2,y2;
for(i=1;i<=n;i++)
for(j=1;i<=n;j++)
{
 cin>>ju[i][j];
 }
cin>>x1>>y1>>x2>>y2;
c=x2;
e=y2;
bfs(x1,y1);
return 0;

}


by _louhc @ 2018-12-29 07:10:41

希望更丰富的展现?使用Markdown


by yi_heng @ 2018-12-29 07:40:23

希望更丰富的展现?使用Markdown


|