Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
136489 | 周震东 | 迷宫问题 | C++ | 解答错误 | 53 | 1 MS | 1224 KB | 987 | 2024-03-09 09:52:51 |
#include <bits/stdc++.h> using namespace std; bool vis[1111][1111]; vector <int> ans[22222]; int m, n, Map[1111][1111], Move[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; void push_ans(int x, int y) { ans[0].push_back(x); ans[1].push_back(y); } bool in(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; } bool dfs(int x, int y) { if (x == m && y == n) { push_ans(m, n); return true; } vis[x][y] = true; for (int i = 0; i < 4; i++) { int tx = x + Move[i][0]; int ty = y + Move[i][1]; if (in(tx, ty) && !vis[tx][ty] && !Map[tx][ty]) { if (dfs(tx, ty)) { push_ans(x, y); return true; } } } return false; } int main() { cin >> m >> n; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { cin >> Map[i][j]; } } if (!dfs(1, 1)) { cout << -1 << endl; } else { for (int i = ans[0].size() - 1; i >= 0; i--) { cout << ans[1][i] << " " << ans[0][i] << endl; } } return 0; }