在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大。
题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积
/**************************************************************
Problem: 1069
User: walfy
Language: C++
Result: Accepted
Time:892 ms
Memory:1360 kb
****************************************************************/ //#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 10007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; struct point{
ll x,y;
};
point p[N],s[N];
int top,n;
ll dir(point p1,point p2,point p3)
{
return (p3.x-p2.x)*(p2.y-p1.y)-(p3.y-p2.y)*(p2.x-p1.x);
}
ll dis(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
ll area(point p1,point p2,point p3)
{
return fabs(dir(p1,p2,p3));
}
bool cmp(point a,point b)
{
ll te=dir(p[],a,b);
if(te<)return ;
if(te==&&dis(p[],a)<dis(p[],b))return ;
return ;
}
void graham()
{
int pos,minx,miny;
minx=miny=inf;
for(int i=;i<n;i++)
{
if(p[i].x<minx||(p[i].x==minx&&p[i].y<miny))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,cmp);
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
top=;
for(int i=;i<=n;i++)
{
while(dir(s[top-],s[top],p[i])>=&&top>=)top--;
s[++top]=p[i];
}
ll ans=;
for(int i=;i<top;i++)
{
int j,a1=(i+)%top,a2=(i+)%top;
for(j=(i+)%top;j!=i;j=(j+)%top)
{
while(a1!=j&&area(s[(a1+)%top],s[i],s[j])>=area(s[a1],s[i],s[j]))a1=(a1+)%top;
while(a2!=i&&area(s[(a2+)%top],s[i],s[j])>=area(s[a2],s[i],s[j]))a2=(a2+)%top;
ans=max(ans,area(s[a1],s[i],s[j])+area(s[a2],s[i],s[j]));
}
}
printf("%.3f\n",1.0*ans/);
}
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%lld%lld",&p[i].x,&p[i].y);
graham();
return ;
}
/******************** ********************/