求调,10个测试点全部 MLE 不知道为什么

B3625 迷宫寻路

DDD_et @ 2024-10-24 19:58:00

rt,代码:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool vis[N][N];
char g[N][N];
int n, m;

struct mzS { int x, y; }; queue <mzS> mq;

string BFS_mz ()
{
    mq.push ({1, 1});
    vis[1][1] = true;
    while (mq.size ())
    {
        auto now = mq.front (); mq.pop ();
        if (now.x == n && now.y == m) return "Yes";
        for (int i = 0; i < 4; i ++)
        {
            int nx = now.x + dx[i];
            int ny = now.y + dy[i];
            if (nx < 0 || ny < 0 || nx > n || ny > m) continue;
            if (vis[nx][ny] || g[nx][ny] == '#') continue;
            mq.push ({nx, ny});
        }
    }
    return "No";
}

int main ()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++) cin >> g[i][j];
    cout << BFS_mz ();
    return 0;
}

评测记录


by imzfx_Square @ 2024-10-24 20:05:42

@DDD_et 你的 vis 除了标记起点数组用了吗


by DDD_et @ 2024-10-24 20:07:44

@imzfx_Square

哦哦哦是的谢谢大佬

此帖结


by imzfx_Square @ 2024-10-24 20:28:29

@DDD_et 其实我以前写广搜的时候也是这样的,正好看到了(


by DDD_et @ 2024-10-24 20:31:06

@imzfx_Square

广搜确实有挺多注意事项的 我之前已经在 vis 数组上寄过一次了,结果这次又寄了


by QwQlaoda @ 2024-10-25 00:04:29

入机眼睛不要捐给vis


|