Alex is Right
Time limit1sMemory limit1024 MB
Given two cities on a sphere, find the closest distance from the shortest great-circle flight to the North Pole and check whether it beats both endpoints.
Problem
While on the first leg of their journey to Beijing (China) for the 2018 ACM ICPC World Finals, Alex and Timothy, two of the team members, were in a vigorous debate. The discussion was about their upcoming 13-hour flight from Washington, DC to Beijing. The question was whether the airplane would travel (a) west over the Pacific, (b) east over the Atlantic, or (c) north, then south, passing by the North Pole. Alex argued that the flight would obviously pass relatively close to the North Pole. Timothy, the self-proclaimed "Geometry Master", called this nonsense and said the pilots would never choose such a suboptimal route.
To Timothy's disappointment, once they landed in Washington, DC, Alex pulled up a flight map and showed Timothy, Arup, and Eric (who both supported Timothy's view) that their upcoming flight would indeed fly a route close to the North Pole.
Given the locations of two distinct points (cities) on the earth, calculate the minimum Euclidean distance between the airplane and the North Pole that will be achieved during the shortest possible flight around the surface of the earth between these two cities, and determine whether Alex's claim is correct. Assume that the airplane is a point on the surface of the earth at all times, i.e., the airplane does not have an altitude.
Alex's claim can be formally defined as follows: The minimum Euclidean distance from the airplane to the North Pole, while traveling along an optimal (shortest) flight around the earth, is strictly less than the distance from the North Pole to both the starting and ending points.
The Euclidean distance between two points and is defined as . This is not the same as the arc distance that would need to be traveled along the surface of the earth.
To refresh your memory, below are the conversions from latitude and longitude to Cartesian coordinates on a sphere of radius :
Notes:
- Use km for the radius of the earth in your calculations.
- The North Pole is located at degrees latitude and degrees longitude.
Input
The first line of input consists of a single integer, (), the number of trips Alex and Timothy went on. Each trip consists of two input lines. The first line of each trip contains two space-separated real numbers, latitude and longitude (; ), with exactly digits after the decimal point, giving the latitude and longitude of the departure city. The second line of each trip contains the latitude and longitude of the destination city in the same format.
It is guaranteed that the departure and destination cities are at distinct locations (and not on the North Pole), and that there is exactly one shortest possible flight path between them.
Output
For each trip, output two lines. The first line is either Alex or Timothy, indicating who was right for this trip. The second line is the minimum Euclidean distance between the North Pole and the plane that is reached while flying from the departure city to the destination city. Print the answer with exactly digits after the decimal point. An answer is accepted if its absolute or relative error is at most km. Print a blank line after each trip.
Note #1: Use the value of PI () provided by the library of your chosen language.
Note #2: It is guaranteed that in cases where Alex is right, the absolute difference between the minimum distance along the flight path to the North Pole and the minimum distance to the destination is at least km.