Algorithm/BOJ
[백준/1004] 어린 왕자 (with 파이썬)
Potato potage
2022. 12. 13. 01:28
반응형
✔ 문제
✔ 풀이
import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
x1, y1, x2, y2 = map(int, input().split())
p = int(input())
count = 0
for _ in range(p):
cx, cy, cr = map(int, input().split())
dis1 = math.sqrt((x1 - cx) ** 2 + (y1 - cy) ** 2)
dis2 = math.sqrt((x2 - cx) ** 2 + (y2 - cy) ** 2)
if cr > dis1 and cr > dis2:
pass
elif cr > dis1:
count += 1
elif cr > dis2:
count += 1
print(count)
✔ 후기
1002번과 비슷한 문제인데 진입/이탈 횟수가 추가되는 경우를 잘 생각해야한다.
참고 코드:
https://itstory1592.tistory.com/35#%EB%AC%B-%EC%A-%-C%--%ED%--%--%EC%-D%B-
반응형