No.208 King
タグ : / 解いたユーザー数 380
作問者 :
Problem Statement
The king piece in shogi can move $1$ square in any of $8$ directions.
When it is at $(0,0)$, it can move to any of $(-1,1),(0,1),(1,1),(-1,0),(1,0),(-1,-1),(0,-1),(1,-1)$.
The king is currently on the square $(0,0)$.
You want to move it to the square $(x,y)$ as quickly as possible.
However, an allied pawn is at $(x_2,y_2)$ and is in the way.
Find the minimum number of moves to go from $(0,0)$ to $(x,y)$.
Note that the pawn cannot be moved.
This shogi board is infinitely large, and squares with negative coordinates also exist. (Negative coordinates are not given in the input.)
Input
$x \ y$ $x_2 \ y_2$
Line $1$ contains the coordinates of the destination square, separated by a space.
Line $2$ contains the coordinates of the square where the pawn is, separated by a space.
$0 \le x,y,x_2,y_2 \le 10^9$
$(0,0),(x,y),(x_2,y_2)$ are all distinct.
Output
Output the minimum number of moves to reach $(x,y)$.
Sample
Sample 1
Input
1 1 1 0
Output
1
Sample 2
Input
10 1 1 0
Output
10
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。