본문 바로가기
Algorithm/백준 BOJ

[백준] [Python] #2869 달팽이는 올라가고 싶다

by 은세라 2021. 11. 13.

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

 

2869번: 달팽이는 올라가고 싶다

첫째 줄에 세 정수 A, B, V가 공백으로 구분되어서 주어진다. (1 ≤ B < A ≤ V ≤ 1,000,000,000)

www.acmicpc.net

처음엔 되게 쉬운 문제인줄 알고 문제 그대로 계산만 했다.

하지만 역시 인생 쉽지않았다... 그대로 계산만하니 시간초과가 났다.

 

1차 시도

import sys
sys.stdin = open("input.txt", "r")

a, b, v = map(int, input().split())

ans = 1
while(True):
    v -= a
    if(v <= 0):
        break
    else:
        v += b
        ans += 1

print(ans)

 

그래서 갓구글을 찾아보니

시간 초과가 난다 == 한 번에 계산해서 구해야한다

식을 세우란 뜻이었다.

 

최종 답안

import sys, math
sys.stdin = open("input.txt", "r")

a, b, v = map(int, input().split())

ans = math.ceil((v-b)/(a-b))
print(ans)

 

 

 

참고 : https://yoonsang-it.tistory.com/9#recentComments

'Algorithm > 백준 BOJ' 카테고리의 다른 글

[백준] [Python] #7576 토마토  (0) 2022.02.22
[백준] [Python] #13904 과제  (0) 2022.02.10
[백준] [Python] #1062 가르침  (0) 2021.09.25
[백준] [Python] #14719 빗물  (0) 2021.09.25
[백준] [Python] #9012 괄호  (0) 2021.09.25

댓글