812. Largest Triangle Area
1,題目要求
You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points.
給出一系列的座標點,計算這些座標點所能構成的最大的三角形的面積。
2,題目思路
首先,因為這些座標點並不是只分布在座標軸上的,因此在計算面積時需要直接使用常規的座標三點平面三角計算公式。
而這三個點如何選擇,並沒有太好的解決方案,用窮舉法相對來說是一種可解的方案。
3,程式原始碼
class Solution {
public :
double largestTriangleArea(vector<vector<int>>& points) {
double res = -1;
for(auto m : points)
for(auto n : points)
for(auto p : points)
{
double tmpArea = 0.5 * abs(m[0]*n[1] + n[0]*p[1] + p[0]*m[1] - m[0 ]*p[1] - n[0]*m[1] - p[0]*n[1]);
res = max(res, tmpArea);
}
return res;
}
};
注:
在二維的向量中,對於其中的一個分量是一維向量,因此m[0]表示第一個元素,m[1]表示第二個元素。
相關推薦
812. Largest Triangle Area
1,題目要求 You have a list of points in the plane. Return the area of the largest triangle that can be f
【LeetCode】812. Largest Triangle Area 解題報告(Python)
目錄題目描述題目大意解題方法三重迴圈組合函式日期 題目描述 You have a list of points in the plane. Return the area of the largest triangle that can be formed
[Leetcode] 812. Largest Triangle Area 解題報告
題目: You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points. Example:
[LeetCode] Largest Triangle Area 最大的三角區域
You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points. Example: Input: points = [[0
演算法——Largest Rectangular Area in a HistogramLargest Rectangular Area in a Histogram
題目:給定的直方圖中查詢最大的矩形。假設每個資料的的寬度都為1,高度不同。例如:使用[6, 2, 5, 4, 5, 2,6],來表示 7個直返圖,圖中最大的矩形面積是12。 思路一: 對每個給定的資料的每個點按照順序的左右各算一遍,最後對比每個點的最大值。
[Swift Weekly Contest 118]LeetCode976. 三角形的最大周長 | Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths. If it
Leetcode 976. Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengt
119th LeetCode Weekly Contest Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths. If it
「Leetcode」976. Largest Perimeter Triangle(C++)
mat break triangle size 大於 不能 clas angle largest 分析 好久不刷題真的思維僵化,要考慮到這樣一個結論:如果遞增的三個數\(x_i,x_{i+1},x_{i+2}\)不符合題意,那麽最大的兩邊之差一定大於等於第一條邊,那麽任何比
poj 2559 Largest Rectangle in a Histogram 棧
hist func opc txt class sse typedef ++ limit // poj 2559 Largest Rectangle in a Histogram 棧 // // n個矩形排在一塊,不同的高度,讓你求最大的矩形的面積(矩形緊挨在一起)
【LeetCode】215. Kth Largest Element in an Array
distinct class ted ++ bsp order algo max git 題目: Find the kth largest element in an unsorted array. Note that it is the kth largest eleme
去掉area的虛框
order href this map a標簽 hide area htm area標簽 <area shape="poly" coords="44,44,61,40,77,45,95,55,105,66,57,76,16,62,32,58,27,55,40,50"
215. Kth Largest Element in an Array
ret span self div arr [] 如果 說明 ace 用heap解, 方法1. 維護一個 size = k 的最小堆。當前元如果大於堆頂的元素,那麽說明堆頂的元素肯定小於kth largest element。所以replace他。 1 class
179. Largest Number
number public integer array ons con app complex str1 Given a list of non negative integers, arrange them such that they form the largest
WebAPI HelpPage支持area
tap 處理 mod empty ont cbe ipa option ppa 開篇:對於WebApi研究不是很深,剛開始使用,記錄自己的解決思路,有更好的處理方式或發現我對WebApi理解有不對的地方懇請指正,謝謝! 環境:WebAPI服務、HelpPage,API路由:
[leetcode]Pascal's Triangle
ger cal public == rst array generate span list 問題描寫敘述: Given numRows, generate the first numRows of Pascal‘s triangle. For example, g
[leetcode-515-Find Largest Value in Each Tree Row]
ron 遍歷 vector div spa cto int ges pop You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3
poj 1265 Area(pick 定理)
clu mod href 格子 .org ble gb2312 gb2 col 鏈接:poj 1265 題意:從原點出發,給出一些dx,dy移動增量,終於形成一個多邊形, 求多邊形內部的格點數目,邊上的格點數目 ,以及面積。 補充知識: 1、以格子點為頂點的線段。覆蓋
pascals-triangle-ii
asc ria bsp else if em1 pascal integer ret else //遞歸 public class PascalsTriangleii{ public ArrayList<Integer> getRow(int rowInd
pascals-triangle-i
cal get emp turn row str em1 ++ else //找規律 temp.add(res.get(i - 1).get(j) + res.get(i - 1).get(j + 1)) public class PascalsTriangle{ p