컴공생의 다이어리

[파이썬, Python] 백준 1011번 : Fly me to the Alpha Centauri 본문

Development/Algorithm & Coding Test

[파이썬, Python] 백준 1011번 : Fly me to the Alpha Centauri

컴공 K 2021. 6. 27. 00:01

백준 1011번 : Fly me to the Alpha Centauri

(문제 바로가기)

 

 

내 코드

import sys
t=int(sys.stdin.readline())
for _ in range(t):
    x,y = map(int,sys.stdin.readline().split())
    distance = y-x
    count = 1
    while True:
        if count ** 2 <= distance < (count + 1) ** 2:
            break
        count += 1
    if count ** 2 == distance:
        print((count * 2) - 1)
    elif count ** 2 < distance <= count ** 2 + count:
        print(count * 2)
    else:
        print((count * 2) + 1)
728x90
Comments