#P2358. Shortest Path on Cube Surface
Shortest Path on Cube Surface
Shortest Path on Cube Surface
A unit cube (side length = 1) is given. An ant on the top face needs to crawl to a point on the bottom face along the surface of the cube. The ant is restricted to moving only on the surfaces of the cube.
The coordinates of the starting point (on the top face) and the ending point (on the bottom face) are given in a coordinate system where the origin is located at the center of the respective face. Since each face is a square of side length 1, the valid coordinates on each face lie in the interval \([-0.5, 0.5]\) for both the \(x\) and \(y\) directions.
To solve the problem, one approach is to consider unfolding the cube along one of the lateral faces. In any unfolding, the top face and the bottom face will be separated by the lateral face. Note that the distance from the center of a face to its edge is \(0.5\) and the lateral face has length 1. Hence, when unfolded appropriately, the vertical separation between the two points becomes \(0.5 + 1 + 0.5 = 2\). In general, by reflecting the bottom face appropriately there emerge four candidate straight‐line distances given by:
[ \begin{aligned} D_1 &= \sqrt{(x_1-x_2)^2+(y_1+y_2+2)^2},\[6pt] D_2 &= \sqrt{(x_1-x_2)^2+(y_1+y_2-2)^2},\[6pt] D_3 &= \sqrt{(x_1+x_2)^2+(y_1-y_2+2)^2},\[6pt] D_4 &= \sqrt{(x_1+x_2)^2+(y_1-y_2-2)^2}. \end{aligned} ]
The required shortest distance is the minimum among these four distances:
[ D=\min{D_1,D_2,D_3,D_4}. ]
Output the result rounded to three decimal places.
inputFormat
Input consists of four real numbers: \(x_1\) and \(y_1\), the coordinates of the starting point on the top face, followed by \(x_2\) and \(y_2\), the coordinates of the ending point on the bottom face. The numbers are separated by spaces.
outputFormat
Output a single real number representing the shortest distance the ant must crawl, rounded to three decimal places.
sample
0 0 0 0
2.000