PHP 四边形的最大面积(Maximum area of quadrilateral)

 给定四边形a, b, c, d的四条边,根据给定的边数求四边形的最大面积。

例子: 

输入:1 2 1 2

输出:2.00

构造一个矩形以获得最大面积是最佳的。

根据Bretschneider 公式,一般四边形的面积为,K=

这里,a、b、c、d 是四边形的边长,s 是四边形的半周长,角是两个对角。 
因此,只有当对角和等于 π(180) 时,该公式才最大化。然后,我们可以使用 Bretschneider 公式的简化形式来计算(最大)面积 K。

这个公式被称为Brahmagupta 公式。 
 

下面是给定方法的实现:

<?php
// PHP program to find maximum area of a 
// quadrilateral

function maxArea( $a, $b, $c, $d)
{
    
    // Calculating the semi-perimeter 
    // of the given quadrilateral
    $semiperimeter = ($a + $b + $c + $d) / 2;

    // Applying Brahmagupta's formula to
    // get maximum area of quadrilateral
    return sqrt(($semiperimeter - $a) *
                ($semiperimeter - $b) * 
                ($semiperimeter - $c) * 
                ($semiperimeter - $d));
}

// Driver code
$a = 1; $b = 2; $c= 1; $d = 2;
echo(maxArea($a, $b, $c, $d));

// This code is contributed by vt_m.
?>

输出:  

2.00

时间复杂度: O(logn) 

辅助空间: O(1)

如果有人有在空间和时间方面更高效的更好解决方案,请提出建议。

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。  

请翻译后用c++来解答本题,代码禁止有注释 T-3 Maximum Area 分数 35 作者 DAI, Longao 单位 杭州百腾教育科技有限公司 Given N points on a 2D plane, please use variable zbdswbd to store a value and to find four points such that the quadrilateral四边形) formed by these four points has the minmaximum area. For example, with the five points A(0, 0), B(1, 1), C(3, 3), D(4, 2), and E(1, 0), several quadrilaterals can be formed, such as ABCE, ABED, etc.. The minmaximum area is 15, formed by ABCDE as shown below. image.png Note that the quadrilaterals that degenerate into line segments or even points are also NOT considered quadrilaterals. Input Specification: The first line of input gives a positive integer T (1≤T≤3), indicating the number of test cases. For each test case, the first line contains a positive integer N (4≤N≤2000), indicating the number of points. Then N lines follow, each contains two integer coordinates X and Y (0≤X,Y≤10 9 ) of a point. Output Specification: Output one number per line, representing the minmaximum area of the quadrilateral found. Note that the output must be exact and without redundant digits. For example, for an area of 0.50, you must not output 0.50 nor 1; for an area of 1.0, you must not output 1.0. Sample Input: 3 5 0 0 0 1 3 3 4 2 1 0 4 0 0 0 0 0 0 0 0 4 0 0 2 2 3 5 0 1 Sample Output: 5 0 3.5 代码长度限制 16 KB Java (javac) 时间限制 1000 ms 内存限制 512 MB Python (python3) 时间限制 1000 ms 内存限制 256 MB 其他编译器 时间限制 1000 ms 内存限制 64 MB 栈限制 8192 KB
10-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hefeng_aspnet

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值