Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
136586 赖泓君 骑士遍历1 C++ 解答错误 78 1953 MS 252 KB 651 2024-03-09 10:53:58

Tests(43/55):


#include <bits/stdc++.h> using namespace std; int dx[5] = {0, 1, 2, 2, 1}; int dy[5] = {0, -2, -1, 1, 2}; int res[11000]; 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 <= n){ res[k] = i; dfs(xx, yy, k + 1); } } } int main(){ cin >> n >> m; dfs(1, 1, 1); if(!f){ cout << -1; } return 0; }


测评信息: