Luogu question writing Python language | P1909 Buy a pencil

Learn Python from a young age! Record the questions in the Luogu Python learning and exam preparation process, and record every moment.

Attached is a summary post: Luogu’s Python language | Summary_Blog of a communicator who loves programming-CSDN Blog


[Title description]

Teacher P needs to go to the store to buy n pencils as gifts for children participating in NOIP. She finds that there are 3 packages of pencils in the store. The number of pencils in different packages may be different, and the price may also be different. To be fair, Teacher P decided to only buy pencils in the same package.

The store does not allow the packaging of pencils to be opened, so Teacher P may need to buy more than n pencils to give gifts to the children.

Now Teacher P wants to know how much it costs to buy at least n pencils if the store has enough of each package.

【enter】

The first line contains a positive integer n, representing the number of pencils required.

The next three lines each use 2 positive integers to describe a package of pencils: the first integer represents the number of pencils in this package, and the second integer represents the price of this package.

Ensure that all 7 numbers are positive integers not exceeding 10,000.

【Output】

1 integer, indicating the minimum amount of money that Teacher P needs to spend.

【Input sample】

57 2 2 50 30 30 27

【Output sample】

54

[Detailed code explanation]

n = int(input())  
c1, p1 = [int(i) for i in input().split()]  
c2, p2 = [int(i) for i in input().split()]  
c3, p3 = [int(i) for i in input().split()]  
# 计算第一组铅笔需要花费的金额
if n % c1 == 0:  
    pp = n // c1 * p1  
else: 
    pp = (n // c1 + 1) * p1  
minn = pp 
# 计算第二组铅笔需要花费的金额
if n % c2 == 0:  
    pp = n // c2 * p2 
else:
    pp = (n // c2 + 1) * p2 
if minn > pp:  
    minn = pp 
# 计算第二组铅笔需要花费的金额
if n % c3 == 0: 
    pp = n // c3 * p3 
else: 
    pp = (n // c3 + 1) * p3  
if minn > pp:
    minn = pp 
print(minn)

【operation result】

9998
128 233
128 2333
128 666
18407

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132778312