Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
79355 彭士宝 方阵填数 Python3 Accepted 33 MS 3828 KB 412 2024-07-03 21:37:39

Tests(3/3):


Code:

n = int(input()) x, y = 0, n - 1 a = [[0] * n for _ in range(n)] i = 1 dirs = [(1, 0), (0, -1), (-1, 0), (0, 1)] a[x][y] = i while i < n**2: for d in dirs: x, y = x + d[0], y + d[1] while 0 <= x < n and 0 <= y < n and a[x][y] == 0: i += 1 a[x][y] = i x, y = x + d[0], y + d[1] x, y = x - d[0], y - d[1] for row in a: print(*row)