首先,計算你需要多少滿包4。讓他們走開。
full_package_4_count = min(x, y, z) mod 5.
x = x - 5 * full_package_4_count
y = y - 5 * full_package_4_count
z = z - 5 * full_package_4_count
現在,仍有可能是值得買一些包裝4S,即使他們實際上並沒有想買,很多票。
其中可能有多少?
partial_package_4_max = (max(x, y, z) + 4) mod 5
現在循環,每一項嘗試:
best_price = 10000000
for partial_package_4_count = 0 to partial_package_4_max:
-- Calculate how much we have already spent.
price = (full_package_4_count + partial_package_4_count) * 175 * (1-0.15)
-- Work out how many additional tickets we want.
x' = max(0, x - 5 * partial_package_count)
y' = max(0, y - 5 * partial_package_count)
z' = max(0, z - 5 * partial_package_count)
--- Add cost for additional tickets (with a 10% discount for every pack of 5)
price = price + x' mod 5 * 25 * (1-0.10) + x' div 5 * 5
price = price + y' mod 5 * 50 * (1-0.10) + x' div 5 * 10
price = price + y' mod 5 * 100 * (1-0.10) + x' div 5 * 20
if price < best_price
best_price = price
-- Should record other details about the current deal here too.
我不得不查看「中國拍賣」,看看它是一個知名的拍賣系統,或者你只是用中文寫你的網站。事實證明,這是前者:http://en.wikipedia.org/wiki/Chinese_auction :) – 2010-04-02 22:38:10
在你的例子中,他們只能從20美元的門票中獲得10%的折扣嗎?或10%的一切?或數量大於5的門票可享九折優惠? – 2010-04-02 22:40:28
@Jeff B會得到10%的折扣,所以如果我要添加6到20美元的門票,我可以從其中5%獲得10%的折扣 – 2010-04-02 22:43:19