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));	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值