Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
139807 | 吴晨曦 | 迷宫问题 | C++ | 解答错误 | 0 | 2 MS | 284 KB | 694 | 2024-03-25 22:36:12 |
#include <bits/stdc++.h> using namespace std; int n, m; const int N = 101; int a[N][N], vis[N][N], dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; vector <pair <int, int>> road; void dfs(int i, int j, int now) { road.push_back({i, j}); vis[i][j] = true; if (i == n and j == m) { for (auto p : road) cout << p.first << " " << p.second << endl; exit(0); } for (int e = 0; e < 4; e++) { int s = i + dx[e], t = j + dy[e]; if (s <= 0 or t <= 0 or s > n or t > n or vis[s][t] or a[s][t]) continue; dfs(s, t, now + 1); } } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; dfs(1, 1, 1); }