Equidistance
Time limit1sMemory limit128 MB
Given coordinates of locations on a sphere, for each query find the surface distance from a third point to the great circle equidistant from two given points.
- Level
Medium5 of 10
- Topics
- Geometry, Math, Implementation, Simulation
- Solved
- No attempts yet
Problem
Alice and Bob have not met for a long time. Bob is unhappy about this and keeps urging Alice to finally make time for a meeting.
Alice: Maybe we should meet on neutral ground.
Bob: I heard the same thing from you two years ago.
Alice: I know. I just haven't found a suitable place yet that is roughly the same distance from your home and from mine.
Bob: On the surface of a sphere, the locus of points equidistant from two given points is a great circle — the one that meets the great circle through the two points at a right angle, at their midpoint. If you only need approximately equal distances, that becomes a band a few kilometres wide and about 40000 km long. Not all of it is water, so finding a fitting place is perfectly feasible.
Alice: If I let you pick anything, we'll certainly end up in Honolulu.
Bob: Which is not a bad idea. So, may I pick anything?
Alice: As long as I don't have to accept it — but I'm open to suggestions.
Bob: Honolulu?
Alice: Is it even on the locus you just described?
Bob: Not quite…
Now to the facts. Given two locations on Earth's surface, consider the locus of all points equidistant from both — a great circle. For a third given location, compute its surface distance to this locus. Assume Earth is a sphere with a radius of 6378 km.
Input
The input consists of two parts: a list of locations followed by a list of queries.
The location list has up to 100 lines, one location per line. Each line contains a name and two floating-point numbers separated by whitespace: the location's name, its latitude, and its longitude. Names are unique, shorter than 30 characters, and contain no whitespace. Latitudes are between -90 (South Pole) and 90 (North Pole) inclusive. Longitudes are between -180 and 180 inclusive, where negative values lie west of the prime meridian and positive values lie east of it (the prime meridian passes through Greenwich, London). The location list ends with a line containing a single #.
Each line of the query list contains three location names. The first is Alice's home, the second is Bob's home, and the third is a candidate meeting point. The query list ends with a line containing a single #.
Output
For each query, print one line:
M is x km off A/B equidistance.
Replace M with the meeting point's name, A and B with the two home names, and x with the computed surface distance rounded to the nearest integer.
If any of the three locations named in a query does not appear in the location list, print ? in place of the distance.