求助 水题Wa了...qnq

P1746 离开中山路

Rbu_nas @ 2018-12-07 22:34:09

# include <cstdio>
# include <cstdlib>
# include <iostream>
# include <algorithm>
# include <queue>
using namespace std;

struct NODE
{
  int x, y, step;
} ;

const int N=1003;
int n;
int mp[N][N];
int stx, sty, edx, edy;
const int dx[]={1,-1,0,0}, dy[]={0,0,1,-1};

inline void bfs()
{
  queue < NODE > q;
  NODE h; h.x=stx, h.y=sty, h.step=0;
  q.push(h);
  while(!q.empty())
  {
    h=q.front(); q.pop();
    NODE v; v.step=h.step+1;
    for(int i=0; i<4; ++i)
    {
      v.x=h.x+dx[i], v.y=h.y+dy[i];
      if(v.x < 1 || v.x > n || v.y < 1 || v.y > n || mp[v.x][v.y])
        continue;
      mp[v.x][v.y]=1;
      if(v.x == edx && v.y == edy)
      {
        cout << v.step;
        return ; 
      }
      q.push(v);
    }
  }
  return ;
}

int main(void)
{
  cin >> n;
  for(int i=1; i<=n; ++i)
        scanf("%s", mp[i]+1);
  cin >> stx >> sty >> edx >> edy;
  bfs();
  return 0;
}

不知道为啥这组数据无输出啊...哪里错了QAQ

10
0100110100
0001110010
1000000001
1000100011
0000101100
1000001100
1001010011
0000010100
0101010000
1001000001
1 7 10 2

by ⚡小林孑⚡ @ 2018-12-07 22:54:20

qwq实在不会改

#include<iostream>
using namespace std;
long long dt[1005][1005];
long long startx,starty,endx,endy,n;
char a;
bool flag;
void move(int jd)
{
    for(int i=1;i<=n;i++)
    {
        for(int ii=1;ii<=n;ii++)
         {
            if (dt[i][ii]==jd-1)
            {
                if (dt[i-1][ii]==0) {flag=1;dt[i-1][ii]=jd;}
                if (dt[i+1][ii]==0) {flag=1;dt[i+1][ii]=jd;}
                if (dt[i][ii-1]==0) {flag=1;dt[i][ii-1]=jd;}
                if (dt[i][ii+1]==0) {flag=1;dt[i][ii+1]=jd;}
            }
         }
    }
if (flag==0) return;
flag=0;
if (dt[startx][starty]==0) move(jd+1);
else return; 
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
    for(int ii=1;ii<=n;ii++)
     {
        cin>>a;
        if (a-48==1) dt[i][ii]=-1;
        else dt[i][ii]=0;
     }
}
cin>>startx>>starty>>endx>>endy;
dt[endx][endy]=1;
move(2);
if (dt[startx][starty]-1!=-1)  cout<<dt[startx][starty]-1;
} 

by Rbu_nas @ 2018-12-07 23:00:22

@zws666 谢谢,我刚刚找到错误了


by Rbu_nas @ 2018-12-07 23:00:43

int我用的是%s

char就过了


|