해커랭크 Weather Observation Station 18 문제 바로가기 

 

문제 해석

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.

2차원 평면상에서 P1(a,b),  P2(c,d) 두 점이 있음
a는 LAT_N의 최솟값
b는 LONG_W의 최솟값
c는 LAT_N의 최댓값
d는 LONG_W의 최댓값

두 점의 맨해튼 거리를 구하는 쿼리 입력, 그리고 결과는 소수점 4자리까지 반올림.

*맨해튼 거리(Manhattan Distance)
: 축을 따라 직각으로 측정된 두 점 사이의 거리  --> | x1 - x2 | +| y1 - y2 |
즉 이 문제에서는 | a - c | + | b - d |

Input Format

The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.

문제 풀이

SELECT ROUND(ABS(MIN(LAT_N) - MAX(LAT_N)) + ABS(MIN(LONG_W) - MAX(LONG_W)),4)
FROM station

풀이 순서

 

1. a = MIN(LAT_N)

   b = MAX(LAT_N)

   c = MIN(LONG_W)

   d = MAX(LONG_W)

 

2. | a - c | + | b - d |  계산

   절대값은 ABS 함수 사용

 

3. 반올림 ROUND  함수 사용

 

+ Recent posts