[백준/파이썬] 15115번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 15115번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
You own a company that hires painters to paint houses. You can hire as many painters as you want, but for every painter you hire, you have to pay X dollars (independent of how long the painter works on the house). In addition, you have to pay a penalty of D · P dollars overall if it takes D days to finish painting the house. This penalty does not depend on the number of painters you hire; furthermore, even if the time taken is not a whole number of days, you are only penalized for the exact time taken.
All painters paint at the same rate. …
입력 요약
The input consists of a single line containing three space-separated integers K, P, and X (1 ≤ K, P, X ≤ 10,000).
출력 요약
Print, on a single line, the minimum cost to have the house painted, rounded and displayed to exactly three decimal places.
코드
k,p,x=map(int,input().split())
v=200000000
for m in range(1,10001):v=min(v,m*x+k/m*p)
print('%.3f'%v)
설명
핵심은 구현 관점에서 You own a company that hires painters to paint houses. You can hire as many painters as you want, but for every painter you hire, you have to pay X do …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기