gpt4 book ai didi

c - C中具有3个变量的线性方程

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

我的 C 类作业是:

A hyperloop track is built of individual pipe segments of certain length. The track starts and ends with a bulkhead, and there is a bulkhead in-between each two pipe segments. The segments are produced by two different manufacturers(s1 and s2). Lengths of the segments(s1,s2), bulkheads(b), and of the desired track(l) are given. The task is to develop a function that will, based on these 4 parameters, decide whether there are valid combinations of segments and bulkheads that will result in the exact length of the desired track, and, if there are, output the number of these combinations.

Note: two different segments may be equal in their lengths, the length of a bulkhead may also be equal to zero.

我的意见是我应该求解一个包含 3 个变量的线性方程:

(m)*s1 + (n)*s2 + (m+n+1)*b = l

但我不知道应该使用哪种方法来编写高效的代码。

最佳答案

方程式提供了寻找组合的标准。为此编写c代码时,只需要迭代m和n并检查它是否满足l长度。下面是可以提供组合的伪代码

for m = 0 to l/s1
for n = 0 to l/s2
bnum = m + n - 1
if (m*s1 + n*s2 + bnum*b) == l)
print m, n, bnum

关于c - C中具有3个变量的线性方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53320134/

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