相关疑难解决方法(0)

模拟时钟的最短路径算法

我有一个正在进行的家庭作业问题,如果有人能帮助我指出正确的方向,那将是非常好的.

如果我在模拟手表上有两分钟点,如t1(55分钟)和t2(7分钟),我需要计算两点之间的最短步数.

到目前为止我想出的是这两个方程式:

-t1 + t2 + 60 =
    -55 + 7 + 60 
    = 12

t1 - t2 + 60 = 
    55 - 7 + 60 
    = 108

12 is lower then 108, therefore 12 steps is the shortest distance.
Run Code Online (Sandbox Code Playgroud)

如果我比较两个结果并使用最低结果,这似乎工作正常.但是,如果我选择另外两个点,例如让t1 = 39和t2 = 34并将它们插入等式中:

-t1 + t2 + 60 = -39 + 34 + 60 = 55
t1 - t2 + 60 = 39 - 34 + 60 = 35

35 is lower then 55, therefore 35 steps …
Run Code Online (Sandbox Code Playgroud)

algorithm math

3
推荐指数
1
解决办法
772
查看次数

标签 统计

algorithm ×1

math ×1