Weather Observation Station 18

hyeh·2022년 8월 8일
0

알고리즘 문제풀이

목록 보기
4/15

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.


두 점 P1, P2 사이의 맨하탄 거리를 소수 4번째점까지 반올림해서 구하라는 문제였다.

SELECT ROUND(ABS(MIN(lat_n) - MAX(lat_n)) + 
             ABS(MIN(long_w) - MAX(long_w)), 4) 
FROM station;

💡

  • 두 점 사이의 거리는 |x1-x2| + |y1-y2|로 구할 수 있으므로, 이 식을 적용해 |a-c| + |b-d|로 구할 수 있다.
  • 절대값은 ABS() 함수로 구할 수 있다!
profile
좌충우돌 천방지축 룰루랄라 데이터 공부

0개의 댓글