2869번

김범주·2022년 7월 14일
0

백준 파이썬

목록 보기
13/29
post-thumbnail
a, b, c = map(int, input().split())

height = 0
day = 0
while True:
  if height < c:
    height += a
    if height >= c:
      break
    else:
      height -= b
      day += 1
print(day+1)      

하나씩 늘려가면서 도달하면 멈추는 식으로 while문을 작성했는데 늘어나는 단위가 적고 목표가 멀 경우 너무 오래걸려서 시간초과가 떴다.

import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())

while True:
  move = (c-a) // (a-b)
  remain = (c-a) % (a-b)   
  if (remain > 0):
    print(move + 2)
  else:
    print(move + 1)  

방법을 바꿔서 뽑으려고 했는데 생각해보니 이렇게 하면 print가 너무 많이 되어서 출력초과...

정답

import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())


move = (c-a) // (a-b)
remain = (c-a) % (a-b)   
if (remain > 0):
  print(move + 2)
else:
  print(move + 1)  

while문 제거하고 그냥 돌리는 식으로...

profile
개발꿈나무

0개의 댓글