糖逗 发表于 2020-7-2 11:05:24

C++刷LeetCode(812. 最大三角形面积)【数学】

题目描述:
给定包含多个点的集合,从其中取三个点组成三角形,返回能组成的最大三角形的面积。

示例:
输入: points = [,,,,]
输出: 2
解释:
这五个点如下图所示。组成的橙色三角形是最大的,面积为2。


注意:

3 <= points.length <= 50.
不存在重复的点。
 -50 <= points <= 50.
结果误差值在 10^-6 以内都认为是正确答案。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/largest-triangle-area
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。


class Solution {
public:
    double largestTriangleArea(vector<vector<int>>& points) {
      double res = 0;
      int len = points.size();
      for (int i = 0; i < len; i++)
            for (int j = i + 1; j < len; j++)
                for (int k = j + 1; k < len; k++)
                  res = max (res, 0.5 * abs(points * points + points * points + points * points - points * points - points * points - points * points));
      return res;
    }
};


参考链接:https://leetcode-cn.com/problems/largest-triangle-area/solution/cjian-dan-dai-ma-by-orange-32/
页: [1]
查看完整版本: C++刷LeetCode(812. 最大三角形面积)【数学】