首先,最大四边形的四个点一定在凸包上
所以先求凸包
有个结论,若是随机数据,凸包包括的点大约是\(\log_2n\)个
然鹅,此题绝对不会这么轻松,若\(O(n^4)\)枚举,只有50分
所以还是要想正解
旋转卡壳是继承上一个点枚举,所以枚举对角线上的两点,通过旋转卡壳找剩余两点
复杂度\(O(n^2)\)
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<sstream>
#include<cstdlib>
#define QAQ int
#define TAT long long
#define OwO bool
#define ORZ double
#define F(i,j,n) for(QAQ i=j;i<=n;++i)
#define E(i,j,n) for(QAQ i=j;i>=n;--i)
#define MES(i,j) memset(i,j,sizeof(i))
#define MEC(i,j) memcpy(i,j,sizeof(j))
using namespace std;
const QAQ N=200005;
const ORZ eps=1e-8;
QAQ n;
struct Point{
ORZ x,y;
friend Point operator + (Point a,Point b){
Point t;
t.x=a.x+b.x;t.y=a.y+b.y;
return t;
}
friend Point operator - (Point a,Point b){
Point t;
t.x=a.x-b.x;t.y=a.y-b.y;
return t;
}
friend ORZ operator ^ (Point a,Point b){
return a.x*b.y-a.y*b.x;
}
friend ORZ operator * (Point a,Point b){
return a.x*b.x+a.y*b.y;
}
}a[N],s[N];
QAQ top;
ORZ ans;
QAQ sign(ORZ x){
return fabs(x)<=eps ? 0 : (x>0 ? 1 : -1);
}
ORZ dis(Point i,Point j){
return (i.x-j.x)*(i.x-j.x)+(i.y-j.y)*(i.y-j.y);
}
OwO comp(Point i,Point j){
ORZ x=(i-a[1])^(j-a[1]);
return x>0||x==0&&dis(a[1],i)<dis(a[1],j);
}
void Graham(){
QAQ k=1;
F(i,2,n) if(a[i].y<a[k].y||(a[i].y==a[k].y&&a[i].x<a[k].x)) k=i;
swap(a[k],a[1]);
sort(a+2,a+n+1,comp);
s[++top]=a[1];s[++top]=a[2];
F(i,3,n){
while(top>=2&&sign((s[top]-s[top-1]) ^ (a[i]-s[top-1]))<=0) top--; //"<=0" 别忘"="
s[++top]=a[i];
}
}
ORZ cal(Point i,Point j,Point k,Point l){
return (((k-i)^(j-i))+((l-i)^(k-i)))/2.0;
}
ORZ work(){
ORZ ans=0;
s[top+1]=a[1];
F(i,1,top){
QAQ a=i%top+1,b=(i+2)%top+1;
F(j,i+2,top){
while(a%top+1!=j&&(((s[a]-s[i])^(s[j]-s[i])))<(((s[a+1]-s[i])^(s[j]-s[i])))) (a%=top)+=1;
while(b%top+1!=j&&(((s[j]-s[i])^(s[b]-s[i])))<(((s[j]-s[i])^(s[b+1]-s[i])))) (b%=top)+=1;
//注意叉积的前后向量顺序
ans=max(ans,fabs(((s[a]-s[i])^(s[j]-s[i]))+((s[j]-s[i])^(s[b]-s[i]))));
}
}
return ans;
}
QAQ main(){
scanf("%d",&n);
F(i,1,n) scanf("%lf%lf",&a[i].x,&a[i].y);
Graham();
printf("%.3lf\n",work());
return 0;
}