본문 바로가기
Algorithm/BOJ

[BOJ][#] 1002 | 터렛

by 밤초록 2022. 1. 25.
1002 | 터렛
https://www.acmicpc.net/problem/1002

 

 

 

이상 코드

 

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)  # The distance of two circles
    if distance == 0 and r1 == r2 :  # two circles are concentric and have the same radius
        print(-1)
    elif abs(r1-r2) == distance or r1 + r2 == distance:  # internal or external
        print(1)
    elif abs(r1-r2) < distance < (r1+r2) :  # two circles meet at two different points
        print(2)
    else:
        print(0)  # else

 

  • 원의 방정식 사용
  • 자주 사용하는 값은 변수에 넣고 저장
반응형

'Algorithm > BOJ' 카테고리의 다른 글

[BOJ] 17298 | 오큰수  (0) 2022.02.04
[BOJ] 12871 | 무한 문자열  (0) 2022.01.27
[BOJ][#] 1920 | 수 찾기  (0) 2022.01.24
[BOJ] 1918 | 후위 표기식  (0) 2022.01.21
[BOJ] 2846 | 오르막길  (0) 2022.01.19

댓글