Algorithm/BOJ
[백준/1002] 터렛 (with 파이썬)
Potato potage
2022. 12. 12. 15:10
반응형
✔ 문제
✔ 풀이
# https://www.acmicpc.net/problem/1002
import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
x1, y1, r1, x2, y2, r2 = map(int, input().split())
dis = math.sqrt((x1-x2) ** 2 + (y1-y2) ** 2)
if dis == 0 and r1 == r2:
print(-1)
elif abs(r1 - r2) == dis or r1 + r2 == dis:
print(1)
elif abs(r1 - r2) < dis < (r1 + r2):
print(2)
else:
print(0)
✔ 설명
원의 방정식과 중심거리과 두 원의 위치 관계만 알면 풀 수 있는 풀이다.
✔ 후기
물론 난 기억 안나서 찾아봤다 ^_ㅜ... 저거 중딩 때 배웠었던가.. 고1때 배웠었나...
기억이 안나서 설명보면서 손으로 그려가면서 풀었다.
참고 코드:
https://ooyoung.tistory.com/111
백준 1002번 [파이썬] 터렛 : 두 원의 위치관계, 원의 방정식
[Python] 백준 알고리즘 온라인 저지 1002번 : 터렛 Python3 코드 import math n = int(input()) for _ in range(n): x1, y1, r1, x2, y2, r2 = map(int, input().split()) distance = math.sqrt((x1-x2)**2 + (y1-y2)**2) # 두 원의 거리 (원의방정
ooyoung.tistory.com
반응형