求助啊,大佬。

P1746 离开中山路

kqing @ 2019-02-01 11:35:13

include <bits/stdc++.h>

using namespace std;

int const maxn=4000;

int n,xa,ya,xe,ye;

int vis[maxn][maxn];

char ju[maxn][maxn];

int a[maxn*maxn][4];

int dx[6]={0,0,-1,0,1};

int dy[6]={0,-1,0,1,0};

void init()

  {
        cin>>n;
        int i,j;
    for(i=1;i<=n;i++)
    for( j=1;j<=n;j++)
    {
      cin>>ju[i][j];

    } 

  }

void bfs(int x,int y)

 {
     int x3,y3,i;
    int head=0, tail=1;
     a[1][1]=x;
     a[1][2]=y;
     a[1][3]=0;
     vis[x][y]=1;
 do
{
       head++;
 for( i=1;i<=4;i++)
 {

  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&&vis[x3][y3]==0)
 {
   tail++;
  a[tail][1]=x3;
 a[tail][2]=y3;
  a[tail][3]=a[head][3]+1;
  vis[x3][y3]==1;

 if(x3==xe&&y3==ye)
   {
   cout<<a[tail][3]<<endl;
   exit(0);
  }
 }
 }

} while(head<tail);

}

int main()

 { 
 init();
 cin>>xa>>ya>>xe>>ye;
  bfs(xa,ya);

  return 0;
  }

by Kuriyama_Mirai @ 2019-02-01 11:43:37

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


by vocaloid @ 2019-02-01 11:48:16

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


by resftlmuttmotw @ 2019-02-01 11:48:22

@kqing

for(i=1;i<=n;i++)
    for( j=1;j<=n;j++)
    {
      cin>>ju[i][j];

    } 

改成

for(i=1;i<=n;i++)
    for( j=1;j<=n;j++)
    {
      scanf("%1d",&ju[i][j]);

    } 

by kqing @ 2019-02-01 11:48:40

谢谢,我找出来。一个小毛病


by kqing @ 2019-02-01 11:49:33

@resftlmuttmotw 谢了!!☆⌒(*^-゜)v


|