Gemstone's Devlog

[백준] 1011번: Fly me to the Alpha Centauri 본문

Data Structure & Algorithms

[백준] 1011번: Fly me to the Alpha Centauri

Gemstone 2021. 8. 10. 15:33

https://www.acmicpc.net/problem/1011

 

1011번: Fly me to the Alpha Centauri

우현이는 어린 시절, 지구 외의 다른 행성에서도 인류들이 살아갈 수 있는 미래가 오리라 믿었다. 그리고 그가 지구라는 세상에 발을 내려 놓은 지 23년이 지난 지금, 세계 최연소 ASNA 우주 비행

www.acmicpc.net

규칙을 찾는 것이 굉장히 어렵고 또 난해한 문제였다... 

혼자힘으로 풀기 위해서 몇 시간을 쏟았지만 도저히 감이 안와서 구글링을 했다.

from math import sqrt

dist = []

while True:
    try:
        t = int(input())
        break
    except:
        continue

for _ in range(t):
    num1, num2 = input().split()
    dist.append(int(num2)-int(num1))

for dis in dist:
    y = int(sqrt(dis))
    z = y+1
    if y == 1:
        print(dis)
    elif dis >= y*z+1:
        print(y+z)
    elif dis >= y**2+1:
        print(y*2)
    else:
        print(y*2-1)

이 분의 코드가 가장 이해하기가 쉬웠다.

https://zifmfmphantom.tistory.com/14

 

백준 1011번(Fly me to the...) 파이썬(python)으로 해결

특정한 거리를 몇 번의 횟수로 도달할 수 있는지 물어보는 문제입니다. 조건 처음 시작할 때와 마지막에 도착하기 전에는 반드시 1의 거리만 움직일 수 있다. 이전에 k만큼 움직였다면 이후에는

zifmfmphantom.tistory.com