【BZOJ1069】【SCOI2007】—最大土地面积(凸包+旋转卡壳)

传送门

考虑枚举任意 2 2 2个点,那么只需要枚举第二个点的时候旋转卡壳就可以 O ( n ) O(n) O(n)得到最远点对了

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char ch=getchar();
	int res=0,f=1;
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while(isdigit(ch))res=res*10+(ch^48),ch=getchar();
	return res*f;
}
const int N=2005;
const double pi=acos(-1);
const double eps=1e-8;
struct point{
	double x,y;
	point(double a=0,double b=0){
		x=a,y=b;
	}
	friend inline point operator +(const point &a,const point &b){
		return point(a.x+b.x,a.y+b.y);
	}
	friend inline point operator -(const point &a,const point &b){
		return point(a.x-b.x,a.y-b.y);
	}
	friend inline double operator *(const point &a,const point &b){
		return (a.x*b.y-a.y*b.x);
	}
	friend inline point operator *(const point &a,const double &b){
		return point(a.x*b,a.y*b);
	}
	friend inline double operator /(const point &a,const point &b){
		return a.x*b.x+a.y*b.y;
	}
	inline double calc(){
		return sqrt(x*x+y*y);
	}
}p[N],q[N];
inline bool comp(const point &a,const point &b){
	double t=(a-p[1])*(b-p[1]);
	if(t==0)return (a-p[1]).calc()<(b-p[1]).calc();
	return t<0;
}
int n,m,top;
inline void graham()
{
	int k=1;
	for(int i=2;i<=n;i++)
		if(p[k].y>p[i].y||(p[k].y==p[i].y&&p[k].x>p[i].x))
			k=i;
	swap(p[1],p[k]);
	sort(p+2,p+n+1,comp);
	q[++top]=p[1];q[++top]=p[2];
	for(int i=3;i<=n;i++)
	{
		while(top>1&&(p[i]-q[top-1])*(q[top]-q[top-1])<=0)
			top--;
		q[++top]=p[i];
	}
}
double calc(){
	q[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;
		for(int y=x+2;y<=top;y++){
			while(a%top+1!=y&&(q[y]-q[x])*(q[a+1]-q[x])>(q[y]-q[x])*(q[a]-q[x]))
				a=a%top+1;
			while(b%top+1!=x&&(q[b+1]-q[x])*(q[y]-q[x])>(q[b]-q[x])*(q[y]-q[x]))
				b=b%top+1;
			ans=max((q[y]-q[x])*(q[a]-q[x])+(q[b]-q[x])*(q[y]-q[x]),ans);
		}
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lf%lf",&p[i].x,&p[i].y);
	graham();
	printf("%.3lf",calc()/2);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值