題目連結

https://zerojudge.tw/ShowProblem?problemid=a536

https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=2736

參考文章

本題要點

留意空瓶子為「兌換後喝完的空瓶 + 沒有被兌換的空瓶」

參考解答

解一:

截圖 2024-06-21 晚上9.29.05.png

n = int(input())
for _ in range(n):
	e, f, c = map(int, input().split())
	total = 0	# 可以喝幾瓶
	bottles = e + f	# 當前空瓶子數量
	while bottles >= c:
		total += bottles // c	
		bottles = bottles // c + bottles % c	# 兌換後喝完的空瓶 + 沒有被兌換的空瓶

	print(total)

回CPE頁面

CPE