Algorithms
백준 1004. 어린 왕자
Brian Go
2022. 6. 9. 03:09
딱 봤을 때 되게 어려워보여서 쫄았는데, 접근하는 방법만 알면 생각보다 간단했다. 요지는 원이 하나씩 주어지기 때문에, 출발점과 도착점이 하나는 원 안에, 하나는 원 밖에 있는 경우에만 카운트를 해주면 된다.
n = int(input())
for i in range(n):
count = 0
start_x, start_y, dest_x, dest_y = map(int, input().split())
univ = int(input())
for j in range(univ):
x, y, r = map(int, input().split())
d1 = ((start_x - x)**2 + (start_y - y)**2) ** 0.5
d2 = ((dest_x - x)**2 + (dest_y - y)**2) ** 0.5
if (d1 < r and d2 > r) or (d1 > r and d2 < r):
count += 1
print(count)
원의 중심에서부터 출발점과 도착점의 거리를 구하고, 거리를 이용해서 하나는 원 밖, 하나는 원 안에 있는 경우에만 카운트를 해주면 된다.