题目:
题解:
有了上个题的基础我们就知道怎么做了吧,这里有四个点,看看数据范围,我们枚举对角线就可以了,求两侧最大三角形
O(n2)
此题卡常。
代码:
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const double INF=1e18;
const double eps=1e-9;
int dcmp(double x)
{
if (x<=eps && x>=-eps) return 0;
return (x>0)?1:-1;
}
struct po
{
double x,y;
po (double X=0,double Y=0){x=X; y=Y;}
}d[50005],sta[50005];
int n,top;double ans;
bool operator <(const po &a,const po&b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
double cj(po x,po y){return x.x*y.y-x.y*y.x;}
po operator -(po x,po y){return po(x.x-y.x,x.y-y.y);}
void tb()
{
sort(d+1,d+n+1);
top=0;
for (int i=1;i<=n;i++)
{
while (top>1 && dcmp(cj(sta[top]-sta[top-1],d[i]-sta[top-1]))<=0) top--;
sta[++top]=d[i];
}
int k=top;
for (int i=n-1;i>=1;i--)
{
while (top>k && dcmp(cj(sta[top]-sta[top-1],d[i]-sta[top-1]))<=0) top--;
sta[++top]=d[i];
}
if (n>1) top--;
}
void rotating()
{
int j,k,l;
sta[top+1]=sta[1];
for (int i=1;i<=top;i++)
{
k=i+1;l=(i+2)%top+1; //
for (int j=i+2;j<=top;j++)
{
double ans1=0;
while (k%top+1<j && dcmp(cj(sta[k]-sta[i],sta[j]-sta[i]) - cj(sta[k+1]-sta[i],sta[j]-sta[i]))<0) k=k%top+1;
ans1+=cj(sta[k]-sta[i],sta[j]-sta[i])/2;
while (dcmp(cj(sta[j]-sta[i],sta[l]-sta[i]) - cj(sta[j]-sta[i],sta[l+1]-sta[i]))<0) l=l%top+1;
ans1+=cj(sta[j]-sta[i],sta[l]-sta[i])/2;
ans=max(ans,ans1);
}
}
}
int main()
{
double x,y;ans=-INF;
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%lf%lf",&x,&y);
d[i]=po(x,y);
}
tb();
rotating();
printf("%.3lf\n",ans);
}