407218: GYM102697 189 Journey to the Exoplanets

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

189. Journey to the Exoplanetstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
This problem is worth 25 points.

You're on an intergalactic space mission in the year 2100, and you come across a star with several planets orbiting it. You know the coordinates of each planet in 3D space, and given this information, you need to find the ordering of the planets from closest to farthest away from the star. Then, you can figure out which planets are most likely to have alien life forms.

You're given the coordinates of the star of the planetary system, and the coordinates for $$$n$$$ planets orbiting the star, and their names.

Recall that you can use the 3D distance formula to calculate the distance between two planets in 3D space:

$$$D$$$ = $$$\sqrt{(X2-X1)^2 + (Y2-Y1)^2 +(Z2-Z1)^2}$$$
Input

The first line of input consists of three space-separated integers: the X, Y, and Z coordinates of the star, respectively.

The next line of input contains a single positive integer $$$n$$$: the number of planets orbiting the star.

The next $$$n$$$ lines each contain three space-separated integers, representing the X, Y, and Z coordinates of each planet, respectively, followed by a space and a single string, representing the name of the planet.

No two planets in the input file will have the same distance away from the star.

Output

Output $$$n$$$ lines: the names of each planet in the exoplanetary system, ordered based on their distance from the star. The planet closest to the star should come first in the list, and the planet the furthest away from the star should come last in the list.

ExampleInput
20 20 20
8
16 19 20 Venus
10 20 20 Mars
14 22 20 Earth
18 20 20 Mercury
-5 17 20 Uranus
2 21 21 Saturn
6 20 23 Jupiter
-11 20 21 Neptune
Output
Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune

加入题单

算法标签: