[알고리즘] 백준 1004번 어린 왕자 python
🦊

[알고리즘] 백준 1004번 어린 왕자 python

Created
2022/07/05
Tags
Algorithm
Python
 
2022-07-05 @이영훈
 
 
 

접근 방법

 
원이 만들어지는 경우는 다음과 같이 4가지 경우가 있습니다
1번과 2번 경우는 원(행성계)의 경계를 거치지 않고 출발점에서 도착점으로 갈 수 있습니다
3번과 4번 경우에는 원의 경계를 거쳐야 출발점에서 도착점으로 갈 수 있습니다
따라서 3번과 4번의 경우인지 확인한 후 count를 증가시키면 됩니다
 
notion image
 
 

파이썬 코드 풀이

 
Python
T = int(input())
for _ in range(T):
    answer = 0

    x1, y1, x2, y2 = map(int, input().split(" "))
    n = int(input())
    for _ in range(n):
        (cx, cy, r) = map(int, input().split(" "))
        is_start_point_in_circle = ((cx - x1) ** 2 + (cy - y1) ** 2) <= r ** 2
        is_arrival_point_in_circle = ((cx - x2) ** 2 + (cy - y2) ** 2) <= r ** 2

        if is_start_point_in_circle is True and is_arrival_point_in_circle is False:
            answer += 1
        elif is_start_point_in_circle is False and is_arrival_point_in_circle is True:
            answer += 1

    print(answer)