์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Python

[BOJ/Step9] 1002 : ํ„ฐ๋ › (Python)

NaNaRin๐Ÿ™ƒ 2021. 2. 15. 19:00

www.acmicpc.net/problem/1002

 

1002๋ฒˆ: ํ„ฐ๋ ›

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค ๋ฅ˜์žฌ๋ช…์ด ์žˆ์„ ์ˆ˜ ์žˆ๋Š” ์œ„์น˜์˜ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ ๋ฅ˜์žฌ๋ช…์ด ์žˆ์„ ์ˆ˜ ์žˆ๋Š” ์œ„์น˜์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋ฌดํ•œ๋Œ€์ผ ๊ฒฝ์šฐ์—๋Š” -1์„ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net


      ์กฐ๊ทœํ˜„๊ณผ ๋ฐฑ์Šนํ™˜์˜ ์ขŒํ‘œ์™€ ๋ฅ˜์žฌ๋ช…๊ณผ์˜ ๊ฑฐ๋ฆฌ๊ฐ€ ๊ฐ๊ฐ ์ฃผ์–ด์กŒ์„ ๋•Œ ๋ฅ˜์žฌ๋ช…์ด ์žˆ์„ ์ˆ˜ ์žˆ๋Š” ์ขŒํ‘œ์˜ ์ˆ˜

== ๋‘ ์ ์˜ ์ขŒํ‘œ์™€ ๋ฐ˜์ง€๋ฆ„์ด ์ฃผ์–ด์กŒ์„ ๋•Œ ๋‘ ์›์˜ ๊ต์ฐจ์ ์˜ ๊ฐœ์ˆ˜

A(x1, y1) ๋ฐ˜์ง€๋ฆ„ r1, B(x2, y2) ๋ฐ˜์ง€๋ฆ„ r2 ์ผ๋•Œ ๋‘ ์ ์˜ ๊ฑฐ๋ฆฌ

distance = ๋ฃจํŠธ(( x1 - x2 )^2 + ( y1 - y2 )^2) ๋ผ ํ•œ๋‹ค.

   1. ๋‘ ์›์ด ์ผ์น˜ํ•  ๋•Œ             : distance == 0 and r1 == r2

   2. ๋‘ ์›์ด ๊ต์ฐจํ•˜์ง€ ์•Š์„ ๋•Œ  : r1 + r2 < distance or r1 - r2 > distance 

   3. ๋‘ ์›์ด 1๋ฒˆ ๊ต์ฐจํ•  ๋•Œ       : r1 - r2 = distance or r1 + r2 = distance

   4. ๋‘ ์›์ด 2๋ฒˆ ๊ต์ฐจํ•  ๋•Œ       : r1 - r2 < distance < r1 + r2

์ด์ง€๋งŒ ์˜ค์ฐจ๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด distance^2,  (r1 - r2)^2, (r1 + r2)^2์„ ๋น„๊ตํ•˜๊ฒ ๋‹ค.

# 1002.py

t = int(input())

for i in range(t):
    x1, y1, r1, x2, y2, r2 = map(int, input().split())
    distance = (x1 - x2) ** 2 + (y1 - y2) ** 2
    add = (r1 + r2) ** 2
    sub = (r1 - r2) ** 2
    if distance == 0 and r1 == r2:
        print(-1)
    elif distance > add or distance < sub:
        print(0)
    elif distance == add or distance == sub:
        print(1)
    else:
        print(2)