Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
180565 黄锦昱 骑士遍历2 C++ 运行超时 9 1000 MS 248 KB 747 2024-08-21 16:08:12

Tests(1/11):


#include<bits/stdc++.h> using namespace std; int n; int vis[15][15]; int dx[] = {0, 1, -1, 1, -1, 2, -2, 2, -2}; int dy[] = {0, 2, 2, -2, -2, 1, 1, -1, -1}; bool flag = 0; void dfs(int x, int y,int num) { vis[x][y] = num; if (num == n * n) { flag = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cout << vis[i][j] << " "; } cout << "\n"; } return; } for (int i = 1; i <= 8; ++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; dfs(cx, cy, num + 1); if (flag) return; } vis[x][y] = 0; } int main() { int x, y; cin >> n >> x >> y; dfs(x, y, 1); if (!flag) cout << -1; }


测评信息: