求解,为何爆0?

P1746 离开中山路

z2415445508 @ 2017-09-24 07:25:11

查了一天的错----蒟蒻

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXM=1010;
struct node
{
  int x,y;
}f[100010];
int n,m,x,y,ex,ey;
bool map[MAXM][MAXM],pd[MAXM][MAXM];
int dx[4]={0,0,-1,1},
  dy[4]={1,-1,0,0};
void bfs()
{
  int head=0,tail=1,step=0;
  f[1].x=x;
  f[1].y=y;
  pd[x][y]=1;
  while(head<tail)
    {
      head++;
      for(int i=0;i<=3;i++)
        {
              int ax=f[head].x+dx[i],
            ay=f[head].y+dy[i];
              if(ax==ex&&ay==ey)
                   {
                  printf("%d",step+1);
                  return;
                    }
              if(ax>=1&&ax<=n&&ay>=1&&ay<=n&&!pd[ax][ay])
                  {
                  pd[ax][ay]=1;
                  step++;
                  tail++;
                  f[tail].x=ax;
                  f[tail].y=ay;
                  }
        }
    }
}
int main()
{
  scanf("%d",&n);
  //for(int i=1;i<=n;i++)for(int j=1,l;j<=n;j++)scanf("%1d",&l),pd[i][j]=l;
  for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        for(int j=0;j<n;j++)
            if(s[j]=='1')
                pd[i][j+1]=1;
    }
  scanf("%d%d%d%d",&x,&y,&ex,&ey);
  if(x==ex&&y==ey)
  {
      printf("0");
      return 0;
  }
  bfs();
  return 0;
}

by z2415445508 @ 2017-09-24 07:52:06

队列开小

此贴终结


by Xxzxx @ 2018-04-30 20:59:15

excuse me???


by Xxzxx @ 2018-04-30 20:59:44

发错贴了……


|