bzoj1069 [SCOI2007]最大土地面积 凸包+单调性

先做凸包 枚举对角线,然后两个指针单调的扫。。

枚举的顺序有时候也会创造性质

注意重点不能选!

码:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int top,i,n,sta[9999],l,r,j;
long double ans;
struct la
{
	double x,y;
}a[100005];
bool cmp(la a,la b)
{
	if(a.x==b.x)return a.y<b.y;
	else return a.x<b.x;
}
long double cj(long double x,long double y,long double xx,long double yy)
{
	return (x*yy-y*xx);
}
int jj(int o)
{
	o=(o+1)%top;
	if(o==0)o=top;
	return o;	
}
void tubao()
{
	sort(a+1,a+1+n,cmp);
	for(i=1;i<=n;i++)
	{
	if(a[i].x==a[i-1].x&&a[i].y==a[i-1].y)continue;
		while(top>1&&cj(a[i].x-a[sta[top]].x , a[i].y-a[sta[top]].y   ,   a[sta[top-1]].x-a[sta[top]].x , a[sta[top-1]].y-a[sta[top]].y)<0)top--;
		sta[++top]=i;
	}
	int lin=top;
	for(i=n-1;i>=1;i--)
	{if(a[i].x==a[i-1].x&&a[i].y==a[i-1].y)continue;
		while(top>lin&&cj(a[i].x-a[sta[top]].x , a[i].y-a[sta[top]].y   ,   a[sta[top-1]].x-a[sta[top]].x , a[sta[top-1]].y-a[sta[top]].y)<0)top--;
		sta[++top]=i;		
	}
	top--;
}
int main()
{
	scanf("%d",&n) ;
	for(i=1;i<=n;i++)
	{
		scanf("%lf%lf",&a[i].x,&a[i].y);
	}
	tubao();
for(i=1;i<=top-3;i++)
{
	l=i+1;r=i+3;
for(j=i+2;j<=top-1;j++)	
{
while(cj(a[sta[jj(l)]].x-a[sta[i]].x,a[sta[jj(l)]].y-a[sta[i]].y,a[sta[j]].x-a[sta[i]].x,a[sta[j]].y-a[sta[i]].y)>   cj(a[sta[l]].x-a[sta[i]].x,a[sta[l]].y-a[sta[i]].y,a[sta[j]].x-a[sta[i]].x,a[sta[j]].y-a[sta[i]].y)  )l=jj(l);	
while(cj(a[sta[j]].x-a[sta[i]].x,a[sta[j]].y-a[sta[i]].y,a[sta[jj(r)]].x-a[sta[i]].x,a[sta[jj(r)]].y-a[sta[i]].y)>   cj(a[sta[j]].x-a[sta[i]].x,a[sta[j]].y-a[sta[i]].y,a[sta[r]].x-a[sta[i]].x,a[sta[r]].y-a[sta[i]].y)  )r=jj(r);	
	ans=max(ans, cj(a[sta[l]].x-a[sta[i]].x,a[sta[l]].y-a[sta[i]].y,a[sta[j]].x-a[sta[i]].x,a[sta[j]].y-a[sta[i]].y)/2+cj(a[sta[j]].x-a[sta[i]].x,a[sta[j]].y-a[sta[i]].y,a[sta[r]].x-a[sta[i]].x,a[sta[r]].y-a[sta[i]].y)/2 );
}		
}	
printf("%.3lf",double(ans));	
}

猜你喜欢

转载自blog.csdn.net/haobang866/article/details/79361689