精華區beta Marginalman 關於我們 聯絡資訊
2024-07-07 1518. Water Bottles There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle. The operation of drinking a full water bottle turns it into an empty bottle. Given the two integers numBottles and numExchange, return the maximum number of water bottles you can drink. 暴力解 每次多喝 B 瓶 每 E 個空瓶可以去換一瓶滿的 會剩下 R 個空瓶 int numWaterBottles(int numBottles, int numExchange) { int count = numBottles; int rest = 0; int tmp_numBottles = 0; while (numBottles + rest >= numExchange) { tmp_numBottles = (numBottles + rest) / numExchange; rest = (numBottles + rest) % numExchange; count += tmp_numBottles; numBottles = tmp_numBottles; } return count; } 一行的數學姐看不懂 有大師能用姆咪也看得懂的方式解釋一下嗎 [Python] One line Math Solution O(1) beating 100% -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 73.173.211.221 (美國) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1720321943.A.C8F.html