题解 | #迷宫问题#
迷宫问题
http://www.nowcoder.com/practice/cf24906056f4488c9ddb132f317e03bc
class maze:
maze = []
row = 0
column = 0
track = []
answer = []
def __init__(self):
self.row , self.column = list(map(int,input().split()))
for _ in range(self.row):
self.maze.append(list(map(int,input().split())))
def go_out(self,pos = (0,0)):
self.track.append(pos)
self.maze[pos[0]][pos[1]] = 1
if pos == (self.row-1,self.column-1):
self.answer = self.track[:]
if pos[0]+1 <= self.row-1 and self.maze[pos[0]+1][pos[1]] != 1:
self.go_out((pos[0]+1,pos[1]))
if pos[1]+1 <= self.column-1 and self.maze[pos[0]][pos[1]+1] != 1:
self.go_out((pos[0],pos[1]+1))
if pos[0]-1 >= 0 and self.maze[pos[0]-1][pos[1]] != 1:
self.go_out((pos[0]-1,pos[1]))
if pos[1]-1 >= 0 and self.maze[pos[0]][pos[1]-1] != 1:
self.go_out((pos[0],pos[1]-1))
self.track.pop()
game = maze()
game.go_out()
for i in game.answer:
print("({0},{1})".format(i[0],i[1]))