gpt4 book ai didi

algorithm - 编程代数方程

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:34:55 24 4
gpt4 key购买 nike

在另一篇文章中,MSN 为我提供了解决代数问题的良好指南 (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

最佳答案

函数简化为:

                  / 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!

由于原始函数是严格递增的,因此这些函数中最多有一个会给出可接受的值。但是对于某些输入,它们都不会提供很好的值(value)。这是因为原始函数会跳过这些值。

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

因此,没有函数会为 cost = 1182 提供可接受的值。

关于algorithm - 编程代数方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/641121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com