카테고리 없음

[백준/파이썬][Bronze IV] Buying in Bulk - 26332

난쟁이 개발자 2025. 1. 23. 15:58
반응형

[Bronze IV] Buying in Bulk - 26332

문제 링크

성능 요약

메모리: 110708 KB, 시간: 276 ms

분류

사칙연산, 수학

제출 일자

2025년 1월 22일 14:44:24

문제 설명

To encourage customers to shop more, some stores charge lower prices if you buy multiples of an item. For example, if you buy one, it may cost you $5 but if you buy two, it will cost you $8 instead of $10.

Let’s assume a store provides discounts as follows:

  1. No discount if you buy only one.
  2. $2 discount for each additional item if you buy more than one.

Given the number of items a customer has purchased and the price for one item, you are to compute the total cost for the customer.

입력

The first input line contains a positive integer, n, indicating the number of customers to check. The customers are on the following n input lines, one customer per line. Each line provides two integers; the first integer c (1 ≤ c ≤ 100) is the number of items purchased by the customer, and the second integer p (3 ≤ p ≤ 50) is the price for one item.

출력

For each customer, print two lines of output. The first line will contain the two input values separated by a single space. The second output line will contain the total cost for the customer. There should be no leading or trailing spaces on any output line.

풀이

def main() :
    # the purchased items, the price
    c, p = map(int, input().split())
    # 구입한 물건 2개 이상부터는 -2 원을 하게 된다.
    func = (c * p) - 2 * (c - 1)
    print(c, p)
    print(func)

T = int(input())
for _ in range(T) :
    main()

전형적인 수학 문제. 

c = 1 이라면
- 2 * (c - 1) = -2 * (1 - 1) 
=> -2 * (0) = 0
이 되기 때문에 이런식으로 수식을 구하면 된다.

아 골드 문제가 브론즈 문제처럼 직관적이고 바로바로 풀리면 얼마나 좋을까. 

반응형