# 最短路径 广义优先搜索 BFS# 所以有时候需要在一些地方踱步,等过了这段时间再前行,就不能简单地限制为进入过的格不能再进入。from collections import deque
visited =[[[0for k inrange(301)]for i inrange(101)]for j inrange(101)]
n, m, t =map(int,input().split())
direct =[[-1,0],[1,0],[0,-1],[0,1]]for i inrange(t):
r, c, a, b =map(int,input().split())for j inrange(a, b +1):
visited[r][c][j]=1defbfs(x, y):
q = deque()
q.append([1,1,0])whilelen(q)!=0:
front = q.popleft()if front[0]== x and front[1]== y:return front[2]for k inrange(4):
row = front[0]+ direct[k][0]
col = front[1]+ direct[k][1]
level = front[2]+1if row <1or row > n or col <1or col > m or visited[row][col][level]:continue
visited[row][col][level]=1
q.append([row, col, level])print(bfs(n, m))
CCF Python题解(60分)201604-4 游戏# 最短路径 广义优先搜索 BFS# 所以有时候需要在一些地方踱步,等过了这段时间再前行,就不能简单地限制为进入过的格不能再进入。from collections import dequevisited = [[[0 for k in range(301)] for i in range(101)] for j in range(1...