代码之家  ›  专栏  ›  技术社区  ›  fbernier

代数方程编程

  •  2
  • fbernier  · 技术社区  · 17 年前

    Calculating bid price from total cost

    usage cost(bid) = PIN(bid*0.10, 10, 50)
    seller cost(bid) = bid*.02
    added cost(bid) = PIN(ceiling(bid/500)*5, 5, 10) + PIN(ceiling((bid - 1000)/2000)*5, 0, 10)
    storing cost(bid) = 100
    So the final cost is something like:
    
    final cost(bid) = PIN(bid*.1, 10, 50) + pin(ceiling(bid/500)*5, 5, 20) + PIN(ceiling((bid - 1000)/2000)*10, 0, 20) + bid*.02 + 100 + bid
    Solve for a particular value and you're done.
    
    For example, if you want the total cost to be $2000:
    
    2000 = PIN(bid*.1, 10, 50) + pin(ceiling(bid/500)*5, 5, 10) + PIN(ceiling((bid - 1000)/2000)*5, 0, 10) + bid*.02 + 100 + bid.
    Bid must be at least > 1500 and < 2000, which works out nicely since we can make those PIN sections constant:
    
    2000 = 50 + 10 + 5 + 100 + bid*1.02
    1835 = bid*1.02
    bid = 1799.0196078431372549019607843137
    
    2 回复  |  直到 9 年前
        1
  •  3
  •   Markus Jarderot    17 年前

                      / 1.02 * bid + 115   bid <   100
                      | 1.12 * bid + 105   bid <=  500
    final cost(bid) = | 1.02 * bid + 160   bid <= 1000
                      | 1.02 * bid + 165   bid <= 3000
                      \ 1.02 * bid + 170   otherwise
    

    bid_a(cost) = (cost - 115) / 1.02
    bid_b(cost) = (cost - 105) / 1.12
    bid_c(cost) = (cost - 160) / 1.02
    bid_d(cost) = (cost - 165) / 1.02
    bid_e(cost) = (cost - 170) / 1.02
    

    例子:

    cost = 2000
    
    bid_a(2000) = (2000 - 115) / 1.02 = 1848  Too big! Need to be < 100
    bid_b(2000) = (2000 - 105) / 1.12 = 1692  Too big! Need to be <= 500
    bid_c(2000) = (2000 - 160) / 1.02 = 1804  Too big! Need to be <= 1000
    bid_d(2000) = (2000 - 165) / 1.02 = 1799  Good. It is <= 3000
    bid_e(2000) = (2000 - 170) / 1.02 = 1794  Too small! Need to be > 3000
    
    Just to check:
    
    final cost(1799) = 1.02 * 1799 + 165 = 2000   Good!
    

    final cost(1000) = 1.02 * 1000 + 160 = 1180
    final cost(1001) = 1.02 * 1001 + 165 = 1186
    

    cost = 1182

        2
  •  2
  •   mweerden    17 年前

    PIN 和 ceiling ,我看不出一个简单的方法来颠倒计算。假设 bid

    x = bid*1.02 + 100 ,我们得出最终成本在x+15(不含)和x+70(含)之间(即。 x+15 < final cost < x+70 70-15=55 投标 x+15 = final cost 和 x+70 = final cost 个人识别码 或 天花板

    222 x+15 = 222 bid = 107/1.02 = 104.90 bid*0.1 额外费用为 5 final cost = bid*0.1 + bid*0.02 + 5 + 100 + bid = bid*1.12 + 105 bid = (222-105)/1.12 = 104.46 .由于此值 投标

    x+70 = 222 bid = 52/1.02 = 50.98 这意味着使用成本 10 final costs = 10 + bid*0.02 + 5 + 100 + bid = bid*1.02 + 115 bid = (222-115)/1.02 = 104.90 投标 104.90

    注意:对于特殊值,我指的是定义使用值和附加成本的函数发生变化的值。例如,对于使用成本,这些值是 100 和 500 50 .