No.48 Controlling the Robot
Problem Statement
Taro is operating a robot remotely.
The robot is currently standing at the coordinates \((0,0)\) and facing north.
Taro now wants to move this robot to the coordinates \((X,Y)\).
As for the commands the robot can perform, you can choose and issue one of the following per \(1\) command.
・Turn in place clockwise by \(90^{\circ}\), changing its facing direction (direction of travel).
・Turn in place counterclockwise by \(90^{\circ}\), changing its facing direction (direction of travel).
・Move forward by distance \(K\) in the direction it is facing. \(K\) can be specified for each command, within the range \((1 \leq K \leq L)\).
Input
X Y L
Line \(1\) contains an integer \(X\ (-10^9 \leq X \leq 10^9)\), the east-west coordinate of the destination. The positive direction is east.
Line \(2\) contains an integer \(Y\ (-10^9 \leq Y \leq 10^9)\), the north-south coordinate of the destination. The positive direction is north.
Line \(3\) contains an integer \(L\ (1 \leq L \leq 10^9)\), the maximum distance the robot can move forward per \(1\) command.
Output
Output the minimum number of commands required for the robot to reach the destination.
Print a newline at the end.
Sample
Sample 1
Input
0 2 1
Output
2
The robot is moved from the coordinates \((0,0)\) to \((0,2)\). In \(1\) forward move, it can advance a distance of \(1\).
Since it is initially facing north, it can reach the destination by issuing the forward command \(2\) times without changing direction.
Sample 2
Input
-7 15 7
Output
5
Facing north, it moves forward by distance \(7\) a total of \(2\) times and by distance \(1\) a total of \(1\) time,
then after rotating counterclockwise by \(90^{\circ}\), it moves forward by distance \(7\) a total of \(1\) time.
It can reach the destination with a total of \(5\) commands.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。