https://www.acmicpc.net/problem/1004
1004번: 어린 왕자
입력의 첫 줄에는 테스트 케이스의 개수 T가 주어진다. 그 다음 줄부터 각각의 테스트케이스에 대해 첫째 줄에 출발점 (x1, y1)과 도착점 (x2, y2)이 주어진다. 두 번째 줄에는 행성계의 개수 n이 주
www.acmicpc.net
https://github.com/stellaluminary/Baekjoon
GitHub - stellaluminary/Baekjoon
Contribute to stellaluminary/Baekjoon development by creating an account on GitHub.
github.com
시작점과 도착점이 원의 내부에 있는지 밖에 있는지가 가장 중요하다.
만약 주어진 각 원에 대하여
1) 둘 다 원 내부에 있다면 굳이 그 원을 고려하지 않아도 되기 때문에 패스
2) 둘 다 원 밖에 있는 것 역시 그 원을 고려하지 않아도 되기 때문에 패스
3) 하나는 원 내부에 있고 하나는 원 밖에 있다면 그 원을 반드시 통과해야 한다.
고로 주어지는 원들에 대하여 하나는 안, 하나는 밖에 존재할 때의 개수를 세면된다.
import sys
input = sys.stdin.readline
def circle(x,y,x1,y1, r):
if (x-x1)**2 + (y-y1)**2 <= r**2:
return 1
else:
return 0
for _ in range(int(input())):
x1,y1,x2,y2 = map(int, input().split())
planet = [list(map(int, input().split())) for _ in range(int(input()))]
cnt = 0
for x,y,r in planet:
if circle(x,y,x1,y1,r) + circle(x,y,x2,y2,r) == 1:
cnt += 1
print(cnt)