BZOJ 1069 [SCOI 2007] 最大土地面积 (凸包+旋转卡壳)

题目链接:BZOJ 1069

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

const int maxn=2000+10;

int N,top;
int L[maxn],R[maxn];

struct node{
	double x,y;
}p[maxn],point,s[maxn];

double get_cross(node a,node b,node c){//get the cross product of vector ab and vector ac.
	return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}

double get_dis(node a,node b){
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

void get_point(){//find the basic point.
	int col=1; point=p[1];
	for(int i=2;i<=N;i++){
		if(p[i].y<point.y || (p[i].y==point.y && p[i].x<point.x)){
			col=i; point=p[i];
		}
	}
	swap(p[1],p[col]);
}

bool cmp(node a,node b){//sort these points by following the clockwise.
	double t=get_cross(point,a,b);
	if(t<0)return true;
	if(t>0)return false;
	double xx=get_dis(point,a),yy=get_dis(point,b);
	return xx<yy;
}

void Graham(){//get the convex hull.
	top=2; s[1]=p[1]; s[2]=p[2];
	for(int i=3;i<=N;i++){
		while(top>=1 && get_cross(s[top-1],s[top],p[i])>=0)top--;
		s[++top]=p[i];
	}
}

void find(){
	s[top+1]=p[1];
	double ans=0;
	int a,b;
	for(int x=1;x<=top;x++)
	{
		a=x%top+1;b=(x+2)%top+1;//because a and b have the monotonicity.
		for(int y=x+2;y<=top;y++)
		{
			while(a%top+1!=y && get_cross(s[x],s[y],s[a+1])>get_cross(s[x],s[y],s[a]))
				a=a%top+1;
			while(b%top+1!=x && get_cross(s[x],s[b+1],s[y])>get_cross(s[x],s[b],s[y]))
				b=b%top+1;
			ans=max(ans,get_cross(s[x],s[y],s[a])+get_cross(s[x],s[b],s[y]));
		}
	}
	printf("%.3lf\n",ans/2);
}

void input(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%lf%lf",&p[i].x,&p[i].y);
	}
}

void solve(){
	get_point();
	sort(p+2,p+N+1,cmp);
	Graham();
	find();
}

int main(){
	input();
	solve();
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值