内容简介:给定一组坐标,返回能组成面积最大的三角形面积。只能套for循环了。利用三边求面积公式得面积。
D77 812. Largest Triangle Area
题目链接
题目分析
给定一组坐标,返回能组成面积最大的三角形面积。
思路
只能套for循环了。利用三边求面积公式得面积。
最终代码
<?php class Solution { /** * @param Integer[][] $points * @return Float */ function largestTriangleArea($points) { $pointAmount = count($points); $max = -1; for($i=0;$i<=$pointAmount;$i++){ for($j=$i+1;$j<$pointAmount;$j++){ for($k=$j+1;$k<$pointAmount;$k++){ $p1 = $points[$i]; $p2 = $points[$j]; $p3 = $points[$k]; $area = abs($p1[0]*$p2[1]+$p2[0]*$p3[1]+$p3[0]*$p1[1]-$p1[0]*$p3[1]-$p2[0]*$p1[1]-$p3[0]*$p2[1])/2; if($area>$max){ $max = $area; } } } } return $max; } }
若觉得本文章对你有用,欢迎用 爱发电 资助。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Coding the Matrix
Philip N. Klein / Newtonian Press / 2013-7-26 / $35.00
An engaging introduction to vectors and matrices and the algorithms that operate on them, intended for the student who knows how to program. Mathematical concepts and computational problems are motiva......一起来看看 《Coding the Matrix》 这本书的介绍吧!