Run ID:77736
提交时间:2024-06-15 11:37:12
N = int(input()) if N <= 100: m = [[0 for _ in range(N)]for _ in range(N)] if N == 1: print(1) else: x,y = 0,N-1 m[x][y] = 1 dx = [1,0,-1,0] dy = [0,-1,0,1] d = 0 for i in range(2,N*N+1): next_x = x + dx[d] next_y = y + dy[d] if not(0 <= next_x < N)or not(0 <= next_y < N) or m[next_x][next_y] != 0: d = (d+1)%4 next_x = x + dx[d] next_y = y + dy[d] x,y = next_x,next_y m[x][y] = i for i in range(N): for j in range(N): print(m[i][j],end =" ") print()