파이썬 알고리즘 112 번 | [백준 1002번] 터렛

Yunny.Log ·2022년 1월 28일
0

Algorithm

목록 보기
115/318
post-thumbnail

112. 터렛

1) 어떤 전략(알고리즘)으로 해결?

구하고자 하는 대상의 위치를 k,l이라고 하면
((x1-k)**2 + (y1-l)**2)**(1/2) == r1
((x2-k)**2 + (y2-l)**2)**(1/2) == r2
여기서 가능한 k,l을 모두 구하는건데..

    ((x1-k)**2 + (y1-l)**2)== r1**2
    ((x2-k)**2 + (y2-l)**2)== r2**2

2) 코딩 설명

<내 풀이>


t=int(input())
for i in range(t) :
    x1, y1, r1, x2, y2, r2 = map(int, input().split())
    distanceOfcenter = ((x1-x2)**2 + (y1-y2)**2)**(1/2)
    if distanceOfcenter  == 0 and r1==r2 :
        print(-1)
    elif abs(r1-r2)<distanceOfcenter < r1+r2:#앞에 r1-r2 절댓값보다 커야한다는 조건있어야 ㅇ
        print(2)
    elif distanceOfcenter == r1+r2 or distanceOfcenter==abs(r1-r2) :
        print(1)
    elif distanceOfcenter > r1+r2 or distanceOfcenter<abs(r1-r2) :
        print(0)

<다른 분의 풀이 or 내 틀린 풀이, 문제점>

출처 : 출처


t=int(input())
for i in range(t) :
    x1, y1, r1, x2, y2, r2 = map(int, input().split())
    distanceOfcenter = ((x1-x2)**2 + (y1-y2)**2)**(1/2)
    if distanceOfcenter  == 0 and r1==r2 :
        print(-1)
    elif abs(r1-r2)<distanceOfcenter < r1+r2:#앞에 r1-r2 절댓값보다 커야한다는 조건있어야 ㅇ
        print(2)
    elif distanceOfcenter == r1+r2 or distanceOfcenter==abs(r1-r2) :
        print(1)
    elif distanceOfcenter > r1+r2 or distanceOfcenter<abs(r1-r2) :
        print(0)


<반성 점>

<배운 점>

0개의 댓글