PROBLEM STATEMENT
Recently you have been working on the pathfinding module for your AI system. Your objective is to
find the shortest path for an agent that wants to travel between two points on a plane. The agent
will start at the point (0,0), and travel to the point (x,y). You decided that the agent will
move either on horizontal of vertical lines such that, at every moment, at least one coordinate of
the agent is an integer.
There is yet another restriction however. Each line will only allow movement in one direction.
All horizontal lines with odd y-coordinates will be directed toward decreasing values of x, and
all other horizontal lines toward increasing values of x. Similarly, all vertical lines with
odd x-coordinates will be directed toward decreasing values of y, and all other vertical lines
toward increasing values of y.
Given x and y, return the distance that the agent must travel.
DEFINITION
Class:Pathfinding
Method:getDirections
Parameters:int, int
Returns:int
Method signature:int getDirections(int x, int y)
CONSTRAINTS
-x and y will both be between -10^6 and 10^6, inclusive.
EXAMPLES
0)
0
-4
Returns: 8
A possible path from (0,0) to (0,-4) is through the points (1,0), (1,-3), (-1,-3) and (-1,-4).
1)
5
-4
Returns: 9
2)
5
4
Returns: 9
3)
-1
-4
Returns: 7
4)
0
0
Returns: 0
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.