from collections import deque

a = [[0]*1010 for _ in range(1010)]
vis = [[False]*1010 for _ in range(1010)]
dir = [[1,0],[-1,0],[0,1],[0,-1]]

class point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

def check(mid):
    global n, m, a, vis, dir
    vis = [[False]*1010 for _ in range(1010)]
    q = deque()
    for i in range(1, m+1):
        q.append(point(1, i))
        vis[1][i] = True
    while q:
        h = q.popleft()
        if h.x == n:
            return True
        for i in range(4):
            tx = dir[i][0] + h.x
            ty = dir[i][1] + h.y
            if tx <= 0 or tx > n or ty <= 0 or ty > m or vis[tx][ty] or a[tx][ty] > mid:
                continue
            q.append(point(tx, ty))
            vis[tx][ty] = True
    return False

n, m = map(int, input().split())
l, r, ans = 1, 0, 1010
for i in range(1, n+1):
    a[i] = list(map(int, input().split()))
    r = max(r, max(a[i]))
while l <= r:
    mid = (l + r) // 2
    if check(mid):
        r = mid - 1
        ans = mid
    else:
        l = mid + 1
print(ans)
``
请用python语言转换下面的c++代码:#includebitsstdc++husing namespace std;int a10101010;bool vis10101010;int dir42=10-10010-1;struct point	int xy;	point	pointint xint yxxyy;int nm;bool checkint mid	memsetvis0sizeof

原文地址: https://www.cveoy.top/t/topic/iF2y 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录