본문 바로가기

개발자의 logs

백준 알고리즘 1011 - 파이썬 본문

공코딩/알고리즘

백준 알고리즘 1011 - 파이썬

주인장v 2022. 6. 27. 15:50
import math
T = int(input())
for _ in range(T):
    x, y = map(int, input().split())
    diff = int(y - x)
    if diff <= 3:
        print(diff)
    else:
        n = int(math.sqrt(diff)) # 제곱근
        if diff == n ** 2:
            print(2*n-1)
        elif n ** 2 < diff <= n ** 2 + n:
            print(2*n)
        else:
            print(2*n+1)

 

문제를 풀다가 도저히 안풀려서 아래 링크를 참고했다.. 

 

문제의 전체적인 플로우는 이해하지만, 내가 스스로 코드를 작성하기에는 아직 익숙하지않다

 

전체적으로 많이 돌려보면서 감을 익혀야겠다

 

https://wlstyql.tistory.com/54

 

백준 알고리즘 1011 (Fly me to the Alpha Centauri) - python

[ 문제 ] 백준 알고리즘 1011 (Fly me to the Alpha Centauri) - python > https://www.acmicpc.net/problem/1011 1011번: Fly me to the Alpha Centauri 우현이는 어린 시절, 지구 외의 다른 행성에서도 인류들..

wlstyql.tistory.com

 

Comments