什么是奇偶剪枝?
比如有一地图:
S...
....
....
....
...D
要求从S点到达D点,此时,从S到D的最短距离为s = abs ( dx - sx ) + abs ( dy - sy )。
如果地图中出现了不能经过的障碍物:
S..X
XX.X
...X
.XXX
...D
此时的最短距离s' = s + 4,为了绕开障碍,不管偏移几个点,偏移的距离都是最短距离s加上一个偶数距离。
其偏移的距离一定是偶数距离,因为一部分远离最短路径,一部分回归最短路径,他们是对称的,必定是一个偶数。如果给你起点和终点的最短距离X,询问Y步能否到达终点,那么Y-X如果不是偶数则必定无法到达!
HDU1010 Tempter of the Bone
Problem Description
The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.
The maze was a rectangle with sizes N by M. There was a door in the maze. At the b