100 Accepted
# | 状态 分数 | 耗时 | 内存占用 |
---|---|---|---|
#1 | Accepted 10 | 35ms | 4 MiB |
#2 | Accepted 10 | 35ms | 4 MiB |
#3 | Accepted 10 | 34ms | 4 MiB |
#4 | Accepted 10 | 37ms | 4 MiB |
#5 | Accepted 10 | 35ms | 3.8 MiB |
#6 | Accepted 10 | 36ms | 3.9 MiB |
#7 | Accepted 10 | 34ms | 3.8 MiB |
#8 | Accepted 10 | 35ms | 4 MiB |
#9 | Accepted 10 | 34ms | 3.9 MiB |
#10 | Accepted 10 | 34ms | 3.8 MiB |
代码
n = int(input())
a = [[0] * (n+1) for _ in range(n+1)] # 创建n+1大小的二维数组,保持1-based索引
h, k, l, b, hy = n-1, 1, 1, 2, 0
for i in range(n):
h = n - hy
l = 1
while l != b:
a[h][l] = k
k += 1
l += 1
l -= 1
while h != n:
h += 1
a[h][l] = k
k += 1
b += 1
hy += 1
for i in range(1, n+1):
for j in range(1, n+1):
print(f"{a[i][j]:4d}", end="")
print()
信息
- 递交者
- 题目
- P369 练63.3 迂回方阵
- 语言
- Python3
- 代码长度
- 456 Bytes
- 递交时间
- 2025-3-19 21:24:05
- 评测时间
- 2025-3-19 21:24:05
- 分数
- 100
- 总耗时
- 350ms
- 峰值时间
- 37ms
- 峰值内存
- 4 MiB