Weather Observation Station 18 | HackerRank
Query the Manhattan Distance between two points, round or truncate to 4 decimal digits.
www.hackerrank.com
Consider P1 (a, b) and P2(a, b) 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.
Input Format
The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.
[My Answer]
#ABS함수로 절대값
#ROUND함수로 소수점
SELECT
ROUND(ABS(MAX(LAT_N) - MIN(LAT_N)) + ABS(MAX(LONG_W) - MIN(LONG_W)), 4)
FROM STATION
오랜만에 본 manhattan distance...
좌표에서의 두점 사이의 절대값을 이용한 거리 찾기
https://ko.wikipedia.org/wiki/%EB%A7%A8%ED%95%B4%ED%8A%BC_%EA%B1%B0%EB%A6%AC
맨해튼 거리 - 위키백과, 우리 모두의 백과사전
맨해튼 거리(Manhattan distance, 혹은 택시 거리, L1 거리, 시가지 거리,Taxicab geometry)는 19세기의 수학자 헤르만 민코프스키가 고안한 용어로, 보통 유클리드 기하학의 거리 공간을 좌표에 표시된 두
ko.wikipedia.org
오랜만에 봐서 신기...
'Code Problems > SQL_ HackerRank' 카테고리의 다른 글
[HackerRank] Weather Observation Station 20 (0) | 2021.12.28 |
---|---|
[HackerRank] Weather Observation Station 19 (0) | 2021.11.26 |
[HackerRank] Weather Observation Station 17 (0) | 2021.11.14 |
[HackerRank] Weather Observation Station 16 (0) | 2021.11.14 |
[HackerRank] Weather Observation Station 15 (0) | 2021.11.11 |