我正在尝试用汇编语言编写一个程序,它接受x和y坐标,x将作为建筑物的位置,y将作为其高度。现在我应该检查一下看得最远的那栋楼。
例如:
正如您在示例中看到的,位置8的建筑物看到的是4米,位置7的建筑物看到的是2米,位置9的建筑物看到的是9米,这是最远的距离,所以我现在要做的就是打印9看到9米,这是最远的距离。我似乎想不出一个算法来做到这一点。
发布于 2017-05-11 04:03:08
从最后到第一,同时跟踪到到目前为止最高的建筑及其位置,以及“目前最好的解决方案”
当你遇到一座新建筑时:
当你开始的时候,给出最好的解决方案。
示例(基于您的示例):
10: highest is 10, so far best is null
9: found new highest, so far best is 10 with distance 1.
8: no new highest, 10 is best.
7: no new highest
...
0: update "best", 9 is the new best with distance of 9.
Yield: 9 as seeing furthest.
https://stackoverflow.com/questions/43901698
复制相似问题