哪位巨佬告诉本蒟蒻这题我为什么会MLE
  • 板块B3625 迷宫寻路
  • 楼主RN_GH
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/8/26 16:44
  • 上次更新2024/8/26 16:55:57
查看原帖
哪位巨佬告诉本蒟蒻这题我为什么会MLE
1413101
RN_GH楼主2024/8/26 16:44

本蒟蒻刚学BFS,请问下面的代码为什么会MLE?```cpp #include<bits/stdc++.h> using namespace std; int n,m; struct Point{ int x,y; }; vector<vector> a; vector fx = { Point{0, 1}, Point{1, 0}, Point{0,-1 }, Point{-1, 0} }; void bfs(Point p) { std::queue q; q.push(p); while(!q.empty()){ Point point = q.front(); q.pop(); for (int j = 0; j < 4; ++j) { int nx = point.x + fx[j].x; int ny = point.y + fx[j].y; if (nx == n && ny == m){ cout << "Yes"; return; } if (nx < 1 || nx > n || ny < 1 || ny > m) { continue; } if (a[nx][ny] = '.') { q.push(Point{nx, ny}); a[nx][ny] = '#'; } } } cout << "No"; }

int main() { cin >> n >> m; a.resize(n + 1, vector(m + 1,0)); for (int i = 1; i <= n; i++){ string str; cin >> str; for (int j = 1; j <= m; j++){ a[i][j] = str[j - 1]; } } bfs({1,1});

return 0;

}

2024/8/26 16:44
加载中...