求DALAO帮助,悬赏3个关注

P1746 离开中山路

```cpp #include<bits/stdc++.h> #define y1 laoqiu_tyxx using namespace std; struct pos { int x; int y; int step; }; char a[1010][1010]; int n,i,j,x1,x2,y1,y2; bool fl=false; bool flag[1010][1010]={false}; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; queue<pos>q; int main() { cin>>n; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { cin>>a[i][j]; } } cin>>x1>>y1; cin>>x2>>y2; q.push({x1,y1,0}); flag[x1][y1]=true; while(!q.empty()) { for(i=0;i<4;i++) { int xx=q.front().x+dx[i]; int yy=q.front().y+dy[i]; int st=q.front().step+1; if(a[xx][yy]=='0'&&((xx>=1&&xx<=n)&&(yy>=1&&yy<=n))&&!flag[xx][yy]) { q.push({xx,yy,st}); flag[xx][yy]=true; if(xx==x2&&yy==y2) { cout<<st; return 0; } } } q.pop(); } } /* 3 5 .##.# .#... ...#. */ ```
by panxz2009 @ 2024-07-03 18:56:00


@[laoqiu_tyxx](/user/1301485) 你的 `st` 变量加了两遍
by panxz2009 @ 2024-07-03 18:57:02


??? ![](https://cdn.luogu.com.cn/upload/image_hosting/is3d827r.png) 这是怎么回事
by laoqiu_tyxx @ 2024-07-03 19:00:24


`y1` 不能作为变量名 @[laoqiu_tyxx](/user/1301485) 你可以像我一样把 `y1` 给 `define` 掉
by panxz2009 @ 2024-07-03 19:02:32


@[panxz2009](/user/169326) 还是超时
by laoqiu_tyxx @ 2024-07-03 19:05:30


?? 你的提交记录在哪 @[laoqiu_tyxx](/user/1301485)
by panxz2009 @ 2024-07-03 19:08:46


代码给我看下
by panxz2009 @ 2024-07-03 19:09:04


@panzx2009 我在本地测的,现在对了
by laoqiu_tyxx @ 2024-07-03 19:10:47


好吧
by panxz2009 @ 2024-07-03 19:11:28


|