[백준/파이썬] 16864번 풀이

업데이트:



문제 정보


풀이

문제

Peter is co-owner of the incredibly successful Pete and Pat’s Pitas and Pizzas and his sales are on fire! But unfortunately, so is his building, due to carelessly laid delivery boxes placed too close to Pete’s famous wood burning pizza oven. After sifting though the remnants, one of the few things Pete is able to salvage is a ledger book, but the only thing he can make out on the charred pages is the profit he made during the last month. The insurance company would like to know how many pitas and how many pizzas Pete actually delivered over that period. …

입력 요약
Input consists of a single line containing 3 values pt p1 p2, where 0 ≤ pt ≤ 10 000.00 is the profit for the month and 0 < p1, p2 ≤ 100.00 are the profits Pete makes on a pita (p1) and on a pizza (p2). All values are in dollars and cents.

출력 요약
Display two integers: the number of pitas sold and the number of pizzas sold so that the total profit equals the value given. If there is more than one combination of pitas and pizzas that give the specified profit, list them all, one combination per line, listing the combination …

코드

import sys;read=sys.stdin.readline
p,a,b=list(map(lambda n:round(float(n)*100),read().split()))
x=0
r=[]
while a*x<=p:
    y=(p-a*x)//b
    if a*x+b*y==p:r.append(f'{x} {y}')
    x+=1
print('\n'.join(r)if r else 'none')

설명

핵심은 구현 관점에서 Peter is co-owner of the incredibly successful Pete and Pat’s Pitas and Pizzas and his sales are on fire! But unfortunately, so is his building, due t …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기