我试图即兴解决问题,在这里给予不同的图层,并且每个图层都在离散范围之间交错颜色,我们必须完全计算这些图层的顶视图。 准确地说,它是如何将不同的图层投影到一个图层中的。计算不同图层的顶视图
例如,
到目前为止我有几个见解,
We need to sort these segments based on ending points (so that I can
sweep linearly from 0 to 6)
Split these sorted items into unit intervals. eg. 0-1 (black), 0-1
(red), 1-2 (red), 2-3 (black), 2-3(green), 3-4 (green), 3-4 (red),
4-5 (red), 5-6 (black)
Push each interval into hashmap and update the color for hashmap for
given interval if it is in a upper layer.
eg. if we push 0-1 (red) (at layer 0) and we encounter 0-1 (black)
(at layer 2) we update map with key 0-1 to black.
Print the map values.
任何想法,从第2步凑合?
你是什么意思*凑合*?什么是确切的输入格式? – syntagma
输入格式可以是元组列表(开始,结束,高度,颜色)。通过即兴创作,我的意思是任何其他最佳解决方案或改进方法。 – everlasto