407185: GYM102697 156 Closest Houses

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

Description

156. Closest Housestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

For this problem, you will be tasked with sorting a series of houses by how close they are to a given house. The rules for house distances are as follows: houses on the same street will have have a distance of the difference between their house numbers, and houses on different streets will experience a distance equal to the difference between their house numbers times the difference between their street numbers. Houses will be each provided with a unique name, such as "h1", and will also have a street number that represents which street they live on as well as a house number that represents their position on the street. For this problem, you will be given a series of houses and their respective values and you will need to determine which house is the closest to a specified house. For example, you may be given h1,h2,h3,h4,h5, then asked to find the closest house to h3.

Input

The first line of input contains a single integer $$$n$$$ that represents the number of houses that are contained in the set. The next $$$n$$$ lines each contain information about a different house in the format: "name streetnum housenum". After $$$n$$$ lines, there will be one line that lists the name of the house that should be used in the nearest house computation.

Output

A single string that represents the house that is closest to the given house name.

ExampleInput
5
h1 1 100
h2 1 2
h3 2 15
h4 5 3
h5 3 7
h5
Output
h3

加入题单

算法标签: