求调,10个测试点全部 MLE 不知道为什么
  • 板块B3625 迷宫寻路
  • 楼主DDD_et
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/10/24 19:58
  • 上次更新2024/10/24 20:51:58
查看原帖
求调,10个测试点全部 MLE 不知道为什么
1205074
DDD_et楼主2024/10/24 19:58

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;
}

评测记录

2024/10/24 19:58
加载中...