bzoj1069[SCOI2007]最大土地面积

先搞出凸包,然后当然枚举两点当成对角线然后旋转卡壳来计算另外两个点与枚举的那两个点所构成的三角形面积的最大值

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#define LL long long 
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
LL read()
{
	LL d=0,f=1;char s=getchar();
	while (s<'0'||s>'9'){if (s=='-')f=-1;s=getchar();}
	while (s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
	return d*f;
}
#define N 2005
#define eps 1e-8
struct dian
{
	double x,y;
}d[N],tb[N];
bool v[N];
double ans;
int n,tot;

double cross(dian a,dian b,dian c)
{
	dian xlab,xlac;
	xlab.x=b.x-a.x;
	xlab.y=b.y-a.y;
	xlac.x=c.x-a.x;
	xlac.y=c.y-a.y;
	return (xlab.x*xlac.y)-(xlac.x*xlab.y);
}

double dis(dian a,dian b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double dx(dian a,dian b,dian c)
{
	dian xlab,xlac;
	xlab.x=b.x-a.x;
	xlab.y=b.y-a.y;
	xlac.x=c.x-a.x;
	xlac.y=c.y-a.y;
	return (xlab.x*xlac.x)+(xlab.y*xlac.y);
}
	
void tubao()
{
	int s=1;memset(v,0,sizeof(v));
	fo(i,2,n)
	{
		if (d[i].x<d[s].x||(d[i].x==d[s].x&&d[i].y<d[s].y)) s=i;
	}
	tot=0;
	int t=s,flag=1;
	while (t!=s||flag==1)
	{
		v[t]=1;
		if (flag) v[t]=0,flag=0;
		if (t==0) break;
		tb[++tot]=d[t];
		int tt=0;
		fo(i,1,n)
		if (v[i]==0)
		{
			tt=i;
			break;
		}
		fo(i,1,n)
		if (v[i]==0&&tt!=i)
		{
			double anss=cross(d[t],d[i],d[tt]);
			if (anss==0&&dis(d[t],d[i])-dis(d[t],d[tt])>eps)
			if (dx(d[i],d[t],d[tt])>0)
			{
				tt=i;
				continue;
			}
			if (anss<0)
			{
				tt=i;
				continue;
			}
		}
		t=tt;
	}
}
		
void RC()
{
	tb[tot+1]=tb[1];
	fo(i,1,tot)
	{
		int a=i%tot+1,b=(i+2)%tot+1;
		fo(j,i+2,tot)
		{
			while (a%tot+1!=j&&fabs(cross(tb[i],tb[j],tb[a]))-fabs(cross(tb[i],tb[j],tb[a%tot+1]))<eps)
				a=a%tot+1;
			while (b%tot+1!=i&&fabs(cross(tb[i],tb[j],tb[b]))-fabs(cross(tb[i],tb[j],tb[b%tot+1]))<eps)
				b=b%tot+1;
			ans=max(ans,abs(cross(tb[i],tb[j],tb[a]))+abs(cross(tb[i],tb[j],tb[b])));
		}
	}
}

int main()
{
	ans=0;
	n=read();
	fo(i,1,n) scanf("%lf%lf",&d[i].x,&d[i].y);
	tubao();
//	fo(i,1,tot) cout<<tb[i].x<<' '<<tb[i].y<<endl;
	RC();
	ans=(double)ans/2;
	cout<<setiosflags(ios::fixed);
    cout.precision(3);
	cout<<ans<<endl;
	return 0;
}


你可能感兴趣的:(计算几何)