第六个点多输出一步,求帮助

P1126 机器人搬重物

我也遇到一样的问题,[看别人的提示](https://www.luogu.org/discuss/show/38030)改成先转弯再走就可以了 想不通为什么=。= 附上我的代码 ```python from collections import deque def read_ints(): return map_list(int, input().strip().split(" ")) def combine(*funs): def wrap_fun(*args, **kwargs): res = funs[0](*args, **kwargs) for fun in funs[1:]: res = fun(res) return res return wrap_fun def mines(num): return lambda it: it - num def map_list(f, l): return list(map(f, l)) n, m = read_ints() arr = [] searched = [] to_search = deque() td = {'N': (0, -1), 'S': (0, 1), 'E': (1, 0), 'W': (-1, 0)} left = {'N': 'W', 'S': 'E', 'E': 'N', 'W': 'S'} right = {'N': 'E', 'S': 'W', 'E': 'S', 'W': 'N'} for i in range(n - 1): l = [] searched.append(l) for j in range(m - 1): l.append({'N': False, 'S': False, 'E': False, 'W': False}) for i in range(n): arr.append(read_ints()) line = input().strip().split(' ') toward = line.pop() sy, sx, dy, dx = map_list(combine(int, mines(1)), line) to_search.append((sx, sy, toward, 0)) searched[sy][sx][toward] = True def add(x, y, t, times): if not (0 <= x < m - 1 and 0 <= y < n - 1): return False if searched[y][x][t]: return False if arr[y][x] + arr[y][x + 1] + arr[y + 1][x] + arr[y + 1][x + 1] > 0: return False to_search.append((x, y, t, times)) searched[y][x][t] = True return True while len(to_search) > 0: x, y, toward, times = to_search.popleft() if (x, y) == (dx, dy): print(times) break tx, ty = td[toward] add(x, y, left[toward], times + 1) add(x, y, right[toward], times + 1) f = add(x + tx * 1, y + ty * 1, toward, times + 1) if f: f = add(x + tx * 2, y + ty * 2, toward, times + 1) if f: add(x + tx * 3, y + ty * 3, toward, times + 1) else: print('-1') ```
by gogomoe @ 2018-05-21 00:05:19


我在线IDE做出来对的,提交又WA。。
by Sober_Clever @ 2018-07-20 21:54:02


求研究抽了的大佬解释一下,我被第六个点卡了半下午,看到讨论改了顺序之后就AC了
by Ciyang @ 2018-08-27 16:38:02


[第六个点可以来我写的题解瞧瞧](https://www.luogu.org/blog/ZeroAC/solution-p1126)
by Zero神 @ 2019-06-02 16:45:46


|