提交时间:2024-08-21 15:31:07
运行 ID: 180522
#include<bits/stdc++.h> using namespace std; int n, m; bool vis[10005][10005]; int dx[5] = {0, 1, 2, 2, 1}; int dy[5] = {0, -2, -1, 1, 2}; bool flag = 0; vector<int> ans; void dfs(int x, int y) { if (x == n && y == m) { flag = 1; for (int i : ans) cout << i << " "; return; } for (int i = 1; i <= 4; ++i) { int cx = x + dx[i], cy = y + dy[i]; if (cx > n || cx < 1) continue; if (cy > n || cy < 1) continue; if (vis[cx][cy]) continue; ans.push_back(i); vis[cx][cy] = 1; dfs(cx, cy); if (flag) return; ans.pop_back(); vis[cx][cy] = 0; } } int main() { cin >> n >> m; dfs(1, 1); }