From 3f534be3dd68b878dd3313558924afe98df511d4 Mon Sep 17 00:00:00 2001 From: Eat-Swap Date: Sun, 15 May 2022 02:05:39 +0800 Subject: [PATCH] add: 220515-CN [cpp] --- cpp/2205/220515-CN.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 cpp/2205/220515-CN.cpp diff --git a/cpp/2205/220515-CN.cpp b/cpp/2205/220515-CN.cpp new file mode 100644 index 0000000..a2be626 --- /dev/null +++ b/cpp/2205/220515-CN.cpp @@ -0,0 +1,22 @@ +#include + +/** + * 812. Largest Triangle Area + * Given an array of points on the X-Y plane points where points[i] = [xi, yi], return the area of the largest triangle that can be formed by any three different points. Answers within 10-5 of the actual answer will be accepted. + */ + +class Solution { +public: + static double largestTriangleArea(std::vector>& points) { + const int n = points.size(); + double ret = 0.0; + for (int i = 0; i < n; ++i) { + for (int j = 1 + i; j < n; ++j) { + for (int k = 1 + j; k < n; ++k) { + ret = std::max(ret, 0.5 * abs(points[i][0] * points[j][1] + points[j][0] * points[k][1] + points[k][0] * points[i][1] - points[i][0] * points[k][1] - points[j][0] * points[i][1] - points[k][0] * points[j][1])); + } + } + } + return ret; + } +};