Lang:Python2
Edit12345678910111213141516171819202122232425262728293031def move(x, y, i):if i == 0:return (x-2, y+1)elif i == 1:return (x-1, y+2)elif i == 2:return (x+1, y+2)elif i == 3:return (x+2, y+1)elif i == 4:return (x+2, y-1)elif i == 5:return (x+1, y-2)elif i == 6:return (x-1, y-2)elif i == 7:return (x-2, y-1)def bfs(f, x, y):f[x][y] = 0queue = [(x, y)]while queue:now_x, now_y = queue.pop(0)for i in xrange(8):next_x, next_y = move(now_x, now_y, i)if 0 <= next_x < 8 and 0 <= next_y < 8 and f[next_x][next_y] == -1:f[next_x][next_y] = f[now_x][now_y] + 1queue.append((next_x, next_y))def solve(position):step = [[[-1]*8 for i in xrange(8)] for k in xrange(3)]