Description
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成
的多边形面积最大。
【题目分析】
好神奇的一道题目,首先肯定的是这四个点是凸包上的点。然后枚举肯定会T,所以可以枚举对角线。然后可以发现更新的时候答案是单调的。然后用旋转卡壳的方法跑一边就可以了。其实是看了Aaron Polaris的题解和标程
【代码】
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <stack>
#include <cmath>
using namespace std;
struct P{
double x,y;
}p[2001];
P s[2001];
int top=0;
double ans;
inline double dcmp(double a)
{
if (fabs(a)<=1e-8) return 0;
else return a>0?1:-1;
}
inline double dis(P a,P b)
{return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
inline P operator - (P a,P b)
{return (P){a.x-b.x,a.y-b.y};}
inline double operator * (P a,P b)
{return a.x*b.y-a.y*b.x;}
inline bool operator<(P a,P b)
{
int x=dcmp((p[1]-a)*(p[1]-b));
if (x==0) return dis(p[1],a)<dis(p[1],b);
else return x>0;
}
int main()
{
int n;
scanf("%d",&n);
for (int i=1;i<=n;++i) scanf("%lf%lf",&p[i].x,&p[i].y);
int t=1;
for (int i=2;i<=n;++i) if (p[i].y<p[t].y||(p[i].y==p[t].y&&p[i].x<p[t].x)) t=i;//扫描一遍,找到起始点
swap(p[1],p[t]);
sort(p+2,p+n+1);
s[++top]=p[1];s[++top]=p[2];
for (int i=3;i<=n;++i)
{
while (top>1&&dcmp((p[i]-s[top-1])*(s[top]-s[top-1]))>=0) top--;//刚开始这里乘反了,结果怎么都是0,找了好久才找到
s[++top]=p[i];
}
s[top+1]=s[1];
int a,b;
for (int x=1;x<top-1;++x)
{
a=x%top+1;b=(x+2)%top+1;
for (int y=x+2;y<=top;++y)
{
while (a%top+1!=y&&dcmp((s[a+1]-s[x])*(s[y]-s[x])-(s[a]-s[x])*(s[y]-s[x]))>0) a=a%top+1;
while (b%top+1!=x&&dcmp((s[y]-s[x])*(s[b+1]-s[x])-(s[y]-s[x])*(s[b]-s[x]))>0) b=b%top+1;
ans=max(ans,(s[a]-s[x])*(s[y]-s[x])+(s[y]-s[x])*(s[b]-s[x]));
}
}
printf("%.3lf\n",ans/2.0);
}