之前没看到n=2000,计算几何自动脑补复杂度必须O(N) O (nlogn)....
然后 打开题解发现可以n^2....
那就简单了,枚举对角线,然后左边找个面积最大的三角形,右边再找一个。
two points 扫过去,那么复杂度还是O(n^2)的。
过样例就A了好爽啊。
#include<bits/stdc++.h>
#define maxl 2010
#define eps 1e-8
using namespace std;
inline int sgn(double x)
{
if(x>-eps && x<eps) return 0;
if(x>0) return 1;
else return -1;
}
struct point
{
double x,y;
point(double a=0,double b=0)
{
x=a;y=b;
}
point operator - (const point b)const
{
return point(x-b.x,y-b.y);
}
bool operator == (const point b) const
{
return sgn(x-b.x)==0 && sgn(y-b.y)==0;
}
inline double norm()
{
return sqrt(x*x+y*y);
}
};
inline double det(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
}
inline double dot(const point &a,const point &b)
{
return a.x*a.x+a.y*a.y;
}
struct polygon_convex
{
vector<point> P;
polygon_convex(int size=0)
{
P.resize(size);
}
}res_convex;
int n;
vector <point> a,res;
double ans;
inline void prework()
{
scanf("%d",&n);
point p;
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&p.x,&p.y);
a.push_back(p);
}
}
inline bool cmp(const point &a,const point &b)
{
if(sgn(a.x-b.x)==0)
return sgn(a.y-b.y)<0;
return sgn(a.x-b.x)<0;
}
polygon_convex convex_hull(vector<point> a)
{
polygon_convex res(2*a.size()+5);
sort(a.begin(),a.end(),cmp);
a.erase(unique(a.begin(),a.end()),a.end());
int m=0,l=a.size();
for(int i=0;i<l;i++)
{
while(m>1 && sgn(det(res.P[m-1]-res.P[m-2],a[i]-res.P[m-2]))<=0)
--m;
res.P[m++]=a[i];
}
int k=m;//l-1号点一定在其中,从l-2开始
for(int i=l-2;i>=0;i--)
{
while(m>k && sgn(det(res.P[m-1]-res.P[m-2],a[i]-res.P[m-2]))<=0)
--m;
res.P[m++]=a[i];
}
res.P.resize(m);
if(a.size()>1)
res.P.resize(m-1);
return res;
}
inline void mainwork()
{
res_convex=convex_hull(a);
res=res_convex.P;
int a,b,nxta,nxtb;n=res.size();
for(int i=0;i<n;i++)
{
a=(i+1)%n;b=(i+3)%n;
for(int j=i+2;j<n;j++)
{
nxta=(a+1)%n;nxtb=(b+1)%n;
while(nxta!=j && sgn(fabs(det(res[i]-res[j],res[nxta]-res[i]))-fabs(det(res[i]-res[j],res[a]-res[i])))>=0)
a=nxta,nxta=(a+1)%n ;
while(nxtb!=i && sgn(fabs(det(res[i]-res[j],res[nxtb]-res[i]))-fabs(det(res[i]-res[j],res[b]-res[i])))>=0)
b=nxtb,nxtb=(b+1)%n;
ans=max(ans,fabs(det(res[i]-res[j],res[b]-res[i]))/2+fabs(det(res[i]-res[j],res[a]-res[i]))/2);
}
}
}
inline void print()
{
printf("%.3f",ans);
}
int main()
{
prework();
mainwork();
print();
return 0;
}