[Python] 1004 어린왕자

유한성·2023년 1월 26일

알고리즘

목록 보기
18/22


문제보기

해결코드

import sys
import math
T = int(sys.stdin.readline().rstrip())

for i in range(T):
    count = 0
    start_x, start_y, dest_x, dest_y = map(int, sys.stdin.readline().rstrip().split())

    n = int(sys.stdin.readline().rstrip())
    for j in range(n):
        dots_x, dots_y, radius = map(int, sys.stdin.readline().rstrip().split())
        d1 = math.sqrt( math.pow(dots_x - start_x , 2) + math.pow(dots_y - start_y , 2))
        d2 = math.sqrt( math.pow(dots_x - dest_x, 2) + math.pow(dots_y - dest_y , 2))

        if ( d1 <=radius and d2 > radius) or (d2<= radius and d1 > radius):
            count += 1

    print(count)


점과 점 사이의 거리를 비교하여 원을 지나는 경우에만 count를 증가시켜 해결하였다.

0개의 댓글