https://www.hackerrank.com/challenges/weather-observation-station-18/problem
Consider P1(a,b)
and P2(c,d)
to be two points on a 2D plane.
a
happens to equal the minimum value in Northern Latitude (LAT_N in STATION).b
happens to equal the minimum value in Western Longitude (LONG_W in STATION).c
happens to equal the maximum value in Northern Latitude (LAT_N in STATION).d
happens to equal the maximum value in Western Longitude (LONG_W in STATION).Query the Manhattan Distance
between points P1 and P2 and round it to a scale of 4 decimal places.
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
select round(abs(c-a)+abs(d-b),4)
from (select min(lat_n) a
from station),
(select min(long_w) b
from station),
(select max(lat_n) c
from station),
(select max(long_w) d
from station);
맨해튼 거리
는 |c-a|+|d-b|
로 구할 수 있다.