LintCode 280: Closest City

280. Closest City

There are many cities on a two-dimensional plane, all cities have their own names c[i]c[i], and location coordinates (x[i],y[i])(x[i],y[i]) (both are integers). There are qq group queries, and each group query gives a city name. You need to answer the city name that is the closest to the city and has the same xx or yy.

Example

Example 1:

 

Input: x = [3, 2, 1] y = [3, 2, 3] c = ["c1", "c2", "c3"] q = ["c1", "c2", "c3"]

Output: ["c3", "NONE", "c1"]

Explanation: For c1, c3 is the same as its y, the closest distance is (3-1)+(3-3)=2

For c2, no city is the same as its x or y

For c3, c1 is the same as his y, the closest distance is (3-1)+(3-3)=2

Notice

If there are multiple answers that satisfy the conditions, the one with the smallest lexicographic name is output.

 

The distance here is the Euler distance: the absolute value of the coordinate difference of xx plus the absolute value of the coordinate difference of yy.

 

0 ≤ Number of cities ≤ 10^5, 

0 ≤ Ask for th

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值