1#AC,9*RE,数组越界不会调

B3625 迷宫寻路

Rtaaa @ 2024-02-03 12:41:42

尽力调了,还是RE

#include<bits/stdc++.h>
using namespace std;
int n,m,q[1000][4],i,j,dx[114]={1,0,-1,0},dy[114]={0,1,0,-1};//0=x 1=y
char a[200][200];
bool b[200][200];
int main(){
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            cin>>a[i][j];
    b[1][1]=true;
    q[1][0]=1;
    q[1][1]=1;
    i=0;j=1;
    while(i<j){
        i++;
        for(int op=0;op<=3;op++){
            j++;
            if(op==0)q[j][0]=q[i][0]-1,q[j][1]=q[i][1];
            if(op==1)q[j][0]=q[i][0]+1,q[j][1]=q[i][1];
            if(op==2)q[j][1]=q[i][1]-1,q[j][0]=q[i][0];
            if(op==3)q[j][1]=q[i][1]+1,q[j][0]=q[i][0];
            if(q[j][0]<=0||q[j][1]<=0||q[j][0]>n||q[j][1]>m){
                j--;
                continue;
            }
            if(b[q[j][0]][q[j][1]]==true||a[q[j][0]][q[j][1]]=='#'){
                j--;
                continue;
            }
            b[q[j][0]][q[j][1]]=true;
            if(q[j][0]==n&&q[j][1]==m){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}

by Bai_cen @ 2024-02-11 11:13:25

试试关掉O2优化?


by Rtaaa @ 2024-02-15 14:21:00

关了没RE了,谢谢,不过为什么才40啊


|