提交时间:2024-08-21 08:22:27

运行 ID: 173707

#include<bits/stdc++.h> using namespace std; const int N = 1e4 + 10; int dx[5] = {0, 1, 2, 2, 1}; int dy[5] = {0, -2, -1, 1, 2}; int res[N]; bool f; int n, m; void dfs(int x, int y, int k){ if(f){ return; } if(x == n && y == m){ f = true; for(int i = 1; i < k; i++) cout << res[i] << " "; return; } if((m - y) > 2 * (n - x)){ return; } int xx, yy; for(int i = 1; i <= 4; i++){ xx = x + dx[i]; yy = y + dy[i]; if(!f && xx >= 1 && xx <= n && yy >= 1 && yy <= m){ res[k] = i; dfs(xx, yy, k + 1); } } } int main(){ cin >> n >> m; dfs(1, 1, 1); if(!f){ cout << -1; } return 0; }