[백준] 1004번 어린 왕자

거북이·2023년 1월 19일
0

백준[실버3]

목록 보기
22/92
post-thumbnail

💡문제접근

  • 행성계 진입/이탈 횟수를 카운팅하는 경우를 아래와 같이 나눠 생각해보았다.
    ①. 출발점이 행성계 안에 존재하고 도착점이 행성계 바깥에 존재하는 경우
    ②. 출발점이 행성계 바깥에 존재하고 도착점이 행성계 안에 존재하는 경우
  • 행성계 진입/이탈 횟수를 카운팅하지 않는 경우는 아래와 같다.
    ①. 출발점과 도착점이 행성계 안에 존재하는 경우
    ②. 출발점과 도착점이 행성계 바깥에 존재하는 경우

💡코드(메모리 : 32540KB, 시간 : 252ms)

import math

T = int(input())
for _ in range(T):
    count = 0
    x1, y1, x2, y2 = map(int, input().split())
    n = int(input())
    for _ in range(n):
        cx, cy, r = map(int, input().split())
        depart_dis = math.sqrt((x1 - cx)**2 + (y1 - cy)**2)
        arrive_dis = math.sqrt((x2 - cx)**2 + (y2 - cy)**2)
        if (depart_dis > r and arrive_dis < r) or (depart_dis < r and arrive_dis > r):
            count += 1
    print(count)

💡소요시간 : 1h

0개의 댓글