60分,只有Yes的样例点过了,悬关

B3625 迷宫寻路

wch666 @ 2023-10-06 14:57:45

#include <bits/stdc++.h>
using namespace std;
int n,m;
char mapp[505][505];
int dl[250005][2];
const int qx[4]={0,0,1,-1};
const int qy[4]={-1,1,0,0};
void BFSS()
{
    int head=0,tail=1,tx,ty;
    mapp[0][0]=1;
    dl[tail][0]=0;
    dl[tail][1]=0;
    while(head != tail)
    {
        head++;
        tx=dl[head][0];
        ty=dl[head][1];
        int newx,newy;
        for(int i=0; i<4; i++)
        {
            newx=tx+qx[i];
            newy=ty+qy[i];
            if(newx < 0 || newx > n+1 || newy < 0 || newy > m+1)
                continue;
            if(mapp[newx][newy] == '*')
                continue;
            mapp[newx][newy]='*';
            tail++;
            dl[tail][0]=newx;
            dl[tail][1]=newy;
        }
    }
}
int main()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            cin>>mapp[i][j];
    BFSS();
    if(mapp[n][m] == '*')
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

by HYLD_WYB @ 2023-10-16 16:14:03

我寻思着题目里也没提到 ‘ * ’啊,不是只有 '#' 和 ‘.’ 吗


|