求求大佬!!!
查看原帖
求求大佬!!!
1296521
Lemon22楼主2024/4/8 22:01
n, m, x1, y1 = map(int, input().split())
q = [[x1 - 1, y1 - 1, 0]]
dirt = [[2, 1], [2, -1], [1, 2], [1, -2], [-1, 2], [-1, -2], [-2, -1], [-2, 1]]
gap = [[-1 for i in range(n)] for j in range(m)]
gap[x1 - 1][y1 - 1] = 0
while q:
    x, y, step = q.pop(0)

    for xx, yy in dirt:
        tx, ty = x + xx, y + yy
        if 0 <= tx < n and 0 <= ty < m and gap[tx][ty] == -1:
            gap[tx][ty] = step + 1
            q.append([tx, ty, step + 1])

for i in gap:
    for j in i:
        print(f"{j:<5}", end="")
    print()

求大佬们看看为什么只能过20,其他全部RE

2024/4/8 22:01
加载中...