Algorithm/백준
[Python] 백준 1002번: 터렛
hanbikan
2021. 4. 19. 10:55
1002번: 터렛
각 테스트 케이스마다 류재명이 있을 수 있는 위치의 수를 출력한다. 만약 류재명이 있을 수 있는 위치의 개수가 무한대일 경우에는 -1을 출력한다.
www.acmicpc.net
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
x1, y1, r1, x2, y2, r2 = map(int, input().split())
distance = ((x1-x2)**2+(y1-y2)**2)**(1/2)
if x1 == x2 and y1 == y2:
if r1 == r2:
print(-1)
else:
print(0)
else:
if distance < r1+r2:
bigR, smallR = max(r1, r2), min(r1, r2)
if distance+smallR < bigR:
print(0)
elif distance+smallR == bigR:
print(1)
else:
print(2)
elif distance == r1+r2:
print(1)
elif distance > r1+r2:
print(0)
위 사진 한 장으로 이해가 되리라고 본다.
중요한 것은, if문 분기를 어떻게 나눌 것인가이다. 나는 우선 두 개의 터렛의 좌표가 겹칠 경우와 그렇지 않을 경우를 나누었다.