【问题标题】:Maximum area of triangle having all vertices of different color具有不同颜色所有顶点的三角形的最大面积
【发布时间】:2017-02-25 23:32:54
【问题描述】:

笛卡尔平面中从 (0,0) 到 (R,C) 的点用 r、g 或 b 着色。用这些点做一个三角形,这样-

a) All three vertices are of different colors.
b) At least one side of triangle is parallel to either of the axes.
c) Area of the triangle is maximum possible.

输出最大可能的区域。 约束:1<=R<=10001<=C<=1000

有人可以告诉我这个问题的方法吗?

【问题讨论】:

  • 你能把原来的问题链接贴在这里吗?

标签: algorithm geometry area


【解决方案1】:

三角形的面积是1/2 * base * height。所以如果三角形的一侧平行于
x 轴,则三角形的底由同一行上的两种颜色组成(尽可能分开),第三种颜色应该在离底最远的行上。因此,您可以对数据进行预处理以查找:

  1. 每种颜色的最顶行和最底行
  2. 每行中每种颜色的最左列和最右列

那么对于每一行,你有十二种可能性来形成一个三角形,例如

left-most-red, right-most-blue, top-most green
left-most-red, right-most-blue, bottom-most green
left-most-red, right-most-green, top-most blue
...

当然,对于一条边平行于 y 轴的三角形,也有相应的过程。

因此,问题可以在 O(R*C) 时间内解决,其中大部分时间都花在了预处理上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-18
    • 2011-06-08
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    相关资源
    最近更新 更多