求助BFS

P1746 离开中山路

@[zhangjingcan](/user/219661) 本人经常眼瞎
by ⚡zhangjingcan⚡ @ 2020-08-30 17:13:24


`a[px][py] > -1`什么鬼?
by Purslane @ 2020-08-30 20:22:17


@[zhangjingcan](/user/219661)
by Purslane @ 2020-08-30 20:22:29


为什么要按照老师模板写呢?我喜欢手写双队列……
by Purslane @ 2020-08-30 20:26:57


看我清奇的马蜂 ```cpp #include<bits/stdc++.h> using namespace std; inline bool id(const char ch) { return ch>='0'&&ch<='9'; } inline int read(void) { int s=0; char ch=getchar(); while(!id(ch)) ch=getchar(); while(id(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar(); return s; } const int MAXN=1000+10; int n,h,t,sx,sy,ex,ey,x[MAXN*MAXN],y[MAXN*MAXN],st[MAXN][MAXN],step[MAXN*MAXN]; const int dx[5]={0,1,-1,0,0},dy[5]={0,0,0,1,-1}; void bfs() { h=1; x[++t]=sx,y[t]=sy; while(h<=t) { int tmpx=x[h],tmpy=y[h++]; for(int i=1;i<=4;i++) { int xx=tmpx+dx[i],yy=tmpy+dy[i]; if(!st[xx][yy]) continue; st[xx][yy]=0; x[++t]=xx,y[t]=yy,step[t]=step[h-1]+1; if(xx==ex&&yy==ey) { printf("%d",step[t]); exit(0); } } } } int main() { n=read(); for(int i=1;i<=n;i++) { string tmp; cin>>tmp; for(int j=0;j<n;j++) if(tmp[j]=='0') st[i][j+1]=1; } sx=read(),sy=read(),ex=read(),ey=read(); bfs(); printf("Chuxu AK IOI!!!"); return 0; } ```
by Purslane @ 2020-08-30 20:37:57


|