@ 各dalao 为什么全RE

P1746 离开中山路

TheSambra @ 2018-03-27 20:33:37

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

const int maxx=2210;
int beginx,beginy,endx,endy,nox,noy,x,y;
int dx[5]={0,0,0,1,-1};
int dy[5]={0,1,-1,0,0};
int step[maxx][maxx];
bool mapp[maxx][maxx];
queue <int> qx;
queue <int> qy;

inline int read(){
  int x=0,f=1;
  char ch=getchar();
  while(ch<'0'||ch>'9'){
    if(ch=='-')
      f=-1;
    ch=getchar();
  }
  while(ch>='0'&&ch<='9'){
    x=x*10+ch-'0';
    ch=getchar();
  }
  return x*f;
}

inline void scan(){
  int n;
  string s;
  n=read();
  for(int i=1;i<=n;i++){
    cin>>s;
    for(int j=0;j<n;j++)
      if(s[j]=='0')
        mapp[i][j+1]=true;
  }  
  beginx=read();
  beginy=read();
  endx=read();
  endy=read();
  qx.push(beginx);
  qy.push(beginy);
  mapp[beginx][beginy]=false;
  return;
}

inline void bfs(){
  while(!qx.empty()){
    nox=qx.front();
    noy=qy.front();
    qx.pop();
    qy.pop();
    if(nox==endx&&noy==endy)
      break;
    for(int i=1;i<=4;i++){
      x=nox+dx[i];
      y=noy+dy[i];
      if(mapp[x][y]==false)
        continue;
      else{
        mapp[x][y]=false;
        step[x][y]=step[nox][noy]+1;
        qx.push(x);
        qy.push(y);
      }
    }
  }
  return;
}

inline void prin(){
  cout<<step[endx][endy];
  return;
}

int main(){
  ios::sync_with_stdio(false);
  scan();
  bfs();
  prin();
  return 0;
}

by HearTheWindSing @ 2019-03-16 19:27:41

莫名觉得你的代码很复杂


|