蒟蒻全WA求助

P1746 离开中山路

各位大佬过来帮帮忙吧
by DWDWDWDW @ 2020-08-27 16:27:23


帮你改完了 ``` #include <iostream> using namespace std; int n,head=0,tail=1,startx,starty,endx,endy,book[1001][1001]; int xx[5]={1,0,-1,0}; int yy[5]={0,-1,0,1}; char k; int mp[1001][1001]; struct note{ int x,y,step; }que[5000001]; int main(){ //ios::sync_with_stdio(false); //cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>k; if(k=='1') mp[i][j]=1; } } cin>>startx>>starty>>endx>>endy; que[1].x=startx; que[1].y=starty; mp[startx][starty]=1; while(head<tail){ head++; for(int i=0;i<4;i++){ int tx=que[head].x+xx[i]; int ty=que[head].y+yy[i]; if(tx>0 && tx<=n && ty>0 && ty<=n && !mp[tx][ty]){ tail++; mp[tx][ty]=1; que[tail].x=tx; que[tail].y=ty; que[tail].step=que[head].step+1; if(tx==endx && ty==endy){cout<<que[tail].step;return 0;} } } } cout<<que[tail-1].step; return 0; } ```
by 沉鸣cmh @ 2020-09-23 20:37:37


|