/*
求四边形面积 + 叉乘的应用
http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=952
题意:有n个点,求这些点能组成的最大四边形面积
思路:两层循环用来枚举每一条线段,分别求线段两边最远的点,即
与该线段所组成的三角形面积最大。该线段也就是四边形的对角线
*/
#include <iostream>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
#define eps 1e-10
#define maxn 310
struct point
{
double x,y;
}Point[maxn];
/*
double cross(point p1,point p2,point p0)///叉乘求三角形的面积
{
double abx = p2.x - p1.x;
double aby = p2.y - p1.y;
double acx = p0.x - p1.x;
double acy = p0.y - p1.y;
return (abx*acy - aby*acx)*0.5;
}*/
//简约版
double cross(point p1,point p2,point p0)///叉乘求三角形的面积
{
return ((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x))*0.5;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0; i<n; i++)
scanf("%lf %lf",&Point[i].x,&Point[i].y);
double ans=0,lmax=0,rmax;
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)///这两个for是枚举对角线的两个点
{
rmax=0,lmax=0;
for(int k=0; k<n; k++)///这是枚举对角线两侧的点
{
if(k!=i && k!=j)
{
double s=cross(Point[i],Point[j],Point[k]);
if(s<eps) lmax=max(lmax,-s);
else rmax=max(rmax,s);
}
}
if(lmax==0 || rmax==0) continue;///判断是否构成四边形
ans=max(ans,(rmax+lmax));///比较各对角线所获的最大四边形的面积
}
}
printf("%.6lf\n",ans);
}
return 0;
}
求最大的四边形面积 + 叉乘的应用
最新推荐文章于 2023-12-29 18:39:43 发布