Distance in Crosses
Time limit2sMemory limit512 MB
Squares are tiled by crosses whose centers form a lattice; moving to a different cross costs one coin, and we must find the minimum coins between two given squares.
- Level
Hard8 of 10
- Topics
- Math, Geometry, Shortest path, Implementation
- Solved
- No attempts yet
Problem
The plane is divided into squares with side . Choose one square and draw coordinate axes from its center parallel to its sides.
Next, draw a cross made up of the central square and its four neighbors, the squares sharing a side with it. Then pick the square centered at and draw another cross made up of this square and its four neighbors. Tile the whole plane with such crosses: their centers lie at the points with coordinates for all integer and . The tiling appears in the figure next to the examples.
Emilia stands at the center of some square on the plane. In one step she can move from a square to one of its neighbors. If a step takes her to a different cross of the tiling, she must pay one coin for that step. Steps that keep her in the same cross are free.
Let the distance in crosses between two squares and be the minimum number of coins Emilia must pay to get from to . You are given the coordinates of two points on the plane: the center of the starting square and the center of the destination square. Find the distance in crosses between them.
Input
The first line contains two integers and , the coordinates of the starting square. The second line contains two integers and , the coordinates of the destination square. The absolute value of every given coordinate does not exceed .
Output
Print one integer: the distance in crosses from the starting square to the destination square.