Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
76938 | 张智博 | 方阵填数 | Python3 | Accepted | 35 MS | 3808 KB | 481 | 2024-06-05 21:09:02 |
n = int(input()) #x,y =0 ,n-1 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)