python代码全是re怎么回事啊
  • 板块P1141 01迷宫
  • 楼主suxiaorui
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/12/21 10:32
  • 上次更新2023/10/28 13:58:43
查看原帖
python代码全是re怎么回事啊
596772
suxiaorui楼主2021/12/21 10:32
import copy
n,m = map(int,input().split())
dx = [-1,0,1,0]
dy = [0,1,0,-1]
g = []
st = [[0] * (n+10) for i in range(n+10)]
for i in range(n):
    g.append(list(map(int,input())))
for i in range(m):
    res = 1
    tmp = copy.deepcopy(st)
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    que = [(a,b)]
    while que:
        x,y = que.pop(0)
        tmp[x][y] = 1
        for j in range(4):
            n_x,n_y = x + dx[j], y + dy[j]
            if  0 <= n_x < n and 0 <= n_y < n and tmp[n_x][n_y] == 0:
                if g[x][y] == 0 and g[n_x][n_y] == 1:
                    que.append((n_x,n_y))
                    res += 1
                    tmp[n_x][n_y] = 1
                elif  g[x][y] == 1 and g[n_x][n_y] == 0:
                    que.append((n_x, n_y))
                    res += 1
                    tmp[n_x][n_y] = 1

    print(res)
    tmp = copy.deepcopy(st)
2021/12/21 10:32
加载中...