import os
import sys
# 请在此输入您的代码
n, m = input().split()
n = int(n)
m = int(m)
arr = [[0 for j in range(m)]for i in range(n)]
r, c = input().split()
r = int(r)
c = int(c)
def do_l():
global n, m, r, c, arr
# 四个方向
# 右下左上
# 行和列的变化
# d = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# 右下左上初始步数
right = m
down = n-1
left = right-1
up = down-1
i = 0
j = -1
k = 0
te = n*m
while k < (n*m)+1:
for ri in range(right):
j += 1
k += 1
arr[i][j] = k
if k == te:
return
for do in range(down):
i += 1
k += 1
arr[i][j] = k
if k == te:
return
for le in range(left):
j -= 1
k += 1
arr[i][j] = k
if k == te:
return
for u in range(up):
i -= 1
k += 1
arr[i][j] = k
if k == te:
return
right -= 2
down -= 2
left -= 2
up -= 2
do_l()
print(arr[r-1][c-1])
# for a in arr:
# print(" ".join(map(str, a)))
标签:arr,right,return,Python,矩阵,蓝桥,int,range,te From: https://blog.csdn.net/zy20221209/article/details/137453981