ACM ICPC World Finals 2009
First, suppose that the sequence of faces that Carl visits on his path is given. In this case, the path length can be found by laying out the triangles in 2-dimensional Cartesian space, connected in the sequence they are visited. The length of the path is then simply given by the length of the line segment from the starting point’s location in the starting face, to the destination point’s location in the destination face. One may object that this is only true provided that the line segment stays inside the laid out triangles, and that, when laid out in the plane, the triangles will not overlap. However, it turns out that, first of all, the triangles will not overlap, and second, if the line segment does not stay inside the triangles, there will in fact be a different way of laying out the triangles such that the line segment stays inside the triangles and becomes shorter.
Now, we are not given the sequence of faces visited, but because the number of faces is so small, one can simply try all possible such sequences.
There are a lot of messy implementation details involved in getting this right. For instance, one has to be able to find the location of a point in a triangle given its azimuth and zenith angles, and when laying out the triangles in the plane one needs to keep track of whether a move from one face to another constitutes a “left” turn or a “right” turn.