解题思路:
讲真,这题数据有点水,要是只给一个凹四边形就gg了。
所以我们假设求出来的是个凸包……。
考虑O(
n2
)枚举对角线,那么就是求以对角线为底上下两个最大的三角形,可以采用旋转卡壳的思想来做,注意到随着对角线转动,最优顶点也在同向转动,所以直接跳指针即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
const int N=2005;
const double eps=1e-8;
struct point
{
double x,y;
point(){}
point(double _x,double _y):
x(_x),y(_y){}
inline friend point operator - (const point &a,const point &b)
{return point(a.x-b.x,a.y-b.y);}
inline friend double operator * (const point &a,const point &b)
{return a.x*b.y-a.y*b.x;}
inline double dis()
{return x*x+y*y;}
}p[N],stk[N];
int n,top;
inline bool cmp(const point &a,const point &b)
{
double det=(a-p[1])*(b-p[1]);
if(det)return det>0;
return (a-p[1]).dis()<(b-p[1]).dis();
}
void graham()
{
int id=1;
for(int i=2;i<=n;i++)
if(p[i].x<p[id].x||p[i].x==p[id].x&&p[i].y<p[id].y)id=i;
swap(p[id],p[1]);
sort(p+2,p+n+1,cmp);
top=-1;
for(int i=1;i<=n;i++)
{
while(top>1&&(p[i]-stk[top])*(stk[top]-stk[top-1])>-eps)top--;
stk[++top]=p[i];
}
top++;
}
void solve()
{
double ans=0;
for(int i=0;i<top;i++)
{
int d=i,u=(i+1)%top;
for(int j=i+1;j<=min(i+top-1,top-1);j++)
{
double a1=abs((stk[d]-stk[i])*(stk[d]-stk[j]));
double a2=abs((stk[u]-stk[i])*(stk[u]-stk[j]));
while((d+1)%top!=j&&abs((stk[(d+1)%top]-stk[i])*(stk[(d+1)%top]-stk[j]))>=a1)
d=(d+1)%top,a1=abs((stk[d]-stk[i])*(stk[d]-stk[j]));
while((u+1)%top!=i&&abs((stk[(u+1)%top]-stk[i])*(stk[(u+1)%top]-stk[j]))>=a2)
u=(u+1)%top,a2=abs((stk[u]-stk[i])*(stk[u]-stk[j]));
ans=max(ans,a1+a2);
}
}
ans*=0.5;
printf("%.3f",ans);
}
int main()
{
//freopen("lx.in","r",stdin);
//freopen("lx.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
graham();
solve();
return 0;
}