컴공생의 다이어리
[파이썬, 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:01728x90
백준 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
반응형
'Development > Algorithm & Coding Test' 카테고리의 다른 글
| [파이썬, Python] 백준 11650번 : 좌표 정렬하기 (0) | 2021.08.19 |
|---|---|
| [파이썬, Python] 백준 1181번 : 단어 정렬 (0) | 2021.08.08 |
| [파이썬, Python] 백준 10757번 : 큰 수 A+B (0) | 2021.06.15 |
| [파이썬, Python] 백준 2839번 : 설탕 배달 (2) | 2021.06.14 |
| [파이썬, Python] 백준 2775번 : 부녀회장이 될테야 (0) | 2021.06.13 |
Comments