我有一个有限的对象供应并作为对象购买,价格上升。因此在N(每N个对象都买,价格上涨的时间)组。当试图购买的对象,什么是计算总成本的最简单的方法是什么?
I have a limited supply of objects and as the objects are purchased, the price goes up accordingly in groups of N (every time N objects are bought, price increases). When trying to purchase a number of objects, what is the easiest way to calculate total cost?
例: 我有24个富。对于每一个N(例如使用3)被购买,价格增加1 所以,如果我买1为1的价格则有23个左右,2人给出在1 价格 1已经购买了之后,有人希望购买6井的总成本是=(2 * 1)+(3×2)+(1 * 3)
Example: I have 24 foo. For every N(example using 3) that are purchased, the price increases by 1. So if I buy 1 at the prices of 1 then there are 23 left and 2 left at the price of 1. After 1 has been purchased, someone wishes to buy 6. Well the total cost would be = (2*1)+(3*2)+(1*3)
OK,我认为这是正确的,现在......
OK, I think that this is correct now...
由于:
X = Total Number of Items Bought
N = Number of Items per Price Increment
B = Base Item Price, before any Increments
I = Price Increment per [N]
设置:
J = FLOOR((X-1)/N)+1
然后:
TotalCost = X*(B-I) + I*(X*J - N*J*(J-1)/2)