728x90
😄 아이디어
1. 선대칭을 통해 일직선 형성 👉 두 좌표 사이의 값 계산
2. 상하좌우 당구대를 활용한 원쿠션 결과를 확인 👉 X축 혹은 Y축에서 동일 선상 위치 시 계산 제한
😄 풀이
def solution(m, n, startX, startY, balls):
answer = []
for ball in balls:
arr = []
if (startY != ball[1] or startX > ball[0]):
arr.append(calcDistance([startX + (m - startX) * 2, startY], ball))
if (startY != ball[1] or startX < ball[0]):
arr.append(calcDistance([-startX, startY], ball))
if (startX != ball[0] or startY > ball[1]):
arr.append(calcDistance([startX, startY + (n - startY) * 2], ball))
if (startX != ball[0] or startY < ball[1]):
arr.append(calcDistance([startX, -startY], ball))
answer.append(min(arr))
return answer
def calcDistance(a, b):
return pow(abs(a[0] - b[0]), 2) + pow(abs(a[1] - b[1]), 2)
✔️ 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/169198