
ZOJ Problem Set  3534
Mike was addicted to a game called "move the mouse" these days. The game was played in a computer. Assume the monitor had W in width and H in height. There was a rectangle of a×b in the screen, whose center had the same position as the mouse. As the mouse moves, the rectangle moved keeping the positions of the center and the mouse the same. Also, you could click the mouse, which made the rectangle rotate 90 degrees clockwise. But there was a constraint that when doing the movement and rotation, any point in the rectangle should NOT get out of the screen, or you will lose the game. Assume the mouse can move only horizonally or vertically(it's not necessary to move integer distance). Here, given the status(position and the direction) of the rectangle in the initial and in the end, you have to work out the minimum distance the mouse has to move to make the rectangle from initial status to the final status. Can you help Mike solve this problem? InputThere are multiple test cases. The first line of each case contains four integers W, H, a, b (0 < a ≤ W, 0 < b ≤ H, W, H ≤ 10^{4}). The second line contains 6 integers x_{1}, y_{1}, t_{1}, x_{2}, y_{2}, t_{2} (0 ≤ x_{1}, x_{2} ≤ W, 0 ≤ y_{1}, y_{2} ≤ H, t_{1}, t_{2} ∈ {1, 2}). (x_{1}, y_{1}) is the initial position and (x_{2}, y_{2}) is the final position. t_{1} and t_{2} are the initial and final directions. 1 represents the rectangle is a×b and 2 represents b×a. OutputIf any point in the rectangle given at the beginning or at the end is already out of the screen, or it's impossible to finish the movement, print one line containing "1" (quotes for clarity), otherwise, print the minimum distance to move in a single line, rounded to 3 digits after the decimal point. Sample Input5 6 1 2 0 3 1 0 3 1 8 8 1 3 1 4 1 4 4 2 Sample Output1 3.000 Author: ZHUANG, Junyuan Contest: ZOJ Monthly, September 2011 