당구연습 (그래프, 구현)

2023. 7. 11. 14:53·Coding Test/programmers
728x90
import sys,math

# 점과 점 사이의 거리 구하는 함수
def dist(x1, y1, x2, y2):
    result = math.sqrt(math.pow(x1-x2,2) + math.pow(y1-y2,2))
    return result

def solution(m, n, startX, startY, balls):
    answer=[]
    for endX, endY in balls:
        minval=sys.maxsize
        # 일직선으로 공이 먼저 부딪히는 경우 빼고 계산
        if not (startX==endX and startY<endY): # 상
            minval = min(minval, dist(startX, 2*n-startY, endX, endY))

        if not (startX==endX and startY>endY): # 하
            minval = min(minval, dist(startX, -startY, endX, endY))

        if not (startY==endY and startX>endX): # 좌
            minval = min(minval, dist(-startX, startY, endX, endY))

        if not (startY==endY and startX<endX): # 우
            minval = min(minval, dist(2*m-startX, startY, endX, endY))
            
		answer.append(round(math.pow(minval,2)))
    
    return answer
728x90
저작자표시 비영리 변경금지 (새창열림)
'Coding Test/programmers' 카테고리의 다른 글
  • 유사 칸토어 비트열
  • 뒤에 있는 큰 수 찾기 (스택)
  • 빛의 경로 사이클 (그래프, 모든 좌표, 네방향 탐색)
  • 2개 이하로 다른 비트 (x보다 큰 1~2비트 다른 가장 작은 수)
Karla Ko
Karla Ko
𝘾𝙤𝙣𝙩𝙞𝙣𝙪𝙤𝙪𝙨𝙡𝙮 𝙄𝙢𝙥𝙧𝙤𝙫𝙞𝙣𝙜, 𝘾𝙤𝙣𝙨𝙩𝙖𝙣𝙩𝙡𝙮 𝘿𝙚𝙫𝙚𝙡𝙤𝙥𝙞𝙣𝙜 𝙔𝙚𝙨!
    250x250
  • Karla Ko
    karlaLog
    Karla Ko
  • 전체
    오늘
    어제
    • Total (467)
      • Spring (19)
      • JPA (4)
      • Cloud & Architecture (15)
        • Kubernetes (5)
        • Docker (3)
        • MSA (2)
        • GCP (1)
        • AWS (4)
      • Devops (1)
      • Message Queue (4)
        • Kafka (2)
        • RabbitMQ (2)
      • Git (4)
      • DB (4)
      • Java (9)
      • Python (4)
      • CS (11)
        • OS (8)
        • Network (2)
        • Algorithm (1)
      • Coding Test (392)
        • programmers (156)
        • Graph (43)
        • DP (37)
        • Search (31)
        • Tree (13)
        • Data Structure (26)
        • Combination (12)
        • Implement (18)
        • Geedy (23)
        • Sort (7)
        • Math (21)
        • geometry (2)
  • 블로그 메뉴

    • 홈
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    알고리즘
    최소신장트리
    LIS
    월간코드챌린지
    백준
    구현
    DP
    최단거리
    동적계획법
    그래프
    트리
    힙
    DFS
    정렬
    재귀
    큐
    자료구조
    구간합
    파이썬
    플로이드워셜
    덱
    스택
    이분탐색
    조합
    다익스트라
    BFS
    최대공약수
    Algorithm
    프로그래머스
    그리디
  • hELLO· Designed By정상우.v4.10.3
Karla Ko
당구연습 (그래프, 구현)
상단으로

티스토리툴바