Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
107820 | 李树强 | 迷宫问题 | C++ | 解答错误 | 13 | 330 MS | 284 KB | 958 | 2023-10-28 11:01:09 |
#include<iostream> #include<vector> using namespace std; const int way[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}, N = 110; //6 7 8 //5 0 1 //4 3 2 int a[N][N], m, n; bool s = false, b[N][N], vis[N][N]; struct xy{int x, y;}; vector<xy> vec; void f(int x, int y){ if(s) return; if(x == m-1 && y == n-1){ s = true; return; } for(int i = 0; i < 4; i++){ int ax = x + way[i][0], ay = y + way[i][1]; if(ax < 0 || ax >= m || ay < 0 || ay >= n) continue; if(b[ax][ay] || vis[ax][ay]) continue; vis[ax][ay] = true; vec.push_back({ax+1, ay+1}); f(ax, ay); if(s) return; vec.pop_back(); vis[ax][ay] = false; } } int main(){ cin >> m >> n; for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cin >> b[i][j]; } } vec.push_back({1, 1}); f(0, 0); for(int i = 0; i < vec.size(); i++) cout << vec[i].x << ' ' << vec[i].y << endl; return 0; }