목차

어린 왕자

ps
링크acmicpc.net/…
출처BOJ
문제 번호1004
문제명어린 왕자
레벨실버 3
분류

기하학

시간복잡도O(T*n)
인풋사이즈T<=?, n<=50
사용한 언어Python
제출기록30860KB / 80ms
최고기록64ms
해결날짜2022/02/24

풀이

코드

"""Solution code for "BOJ 1004. 어린 왕자".

- Problem link: https://www.acmicpc.net/problem/1004
- Solution link: http://www.teferi.net/ps/problems/boj/1004

Tags: [Geometry]
"""

import sys


def main():
    T = int(sys.stdin.readline())
    for _ in range(T):
        x1, y1, x2, y2 = [int(x) for x in sys.stdin.readline().split()]
        n = int(sys.stdin.readline())
        answer = 0
        for _ in range(n):
            cx, cy, r = [int(x) for x in sys.stdin.readline().split()]
            p1 = (x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy) - r * r
            p2 = (x2 - cx) * (x2 - cx) + (y2 - cy) * (y2 - cy) - r * r
            if p1 * p2 < 0:
                answer += 1
        print(answer)


if __name__ == '__main__':
    main()