bzoj1069: [SCOI2007]最大土地面积 计算几何 旋转卡壳

第一次遇到卡精度。。。。要1e-10才行。

先求出凸包,再在凸包上枚举两个切点,另外两个顶点在这两个点的连线的两端找极值点。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define pi acos(-1.0)
#define maxn 410000
#define eps 1e-10
int n,cnt;
struct node
{
    double x,y;
}p[maxn],dir[10];
double ans;
double sqr(double x)
{
    return x*x;
}
double dis(node a,node b)
{
    return (sqr(a.x-b.x)+sqr(a.y-b.y));
}
double operator * (node a,node b)
{
    return a.x*b.y-a.y*b.x;
}
node operator - (node a,node b)
{
    node t;
    t.x=a.x-b.x; t.y=a.y-b.y;
    return t;
}
node operator + (node a,node b)
{
    node t;
    t.x=a.x+b.x; t.y=a.y+b.y;
    return t;
}
bool cmp(node a,node b)
{
    if(fabs((a-p[1])*(b-p[1]))<eps)return dis(p[1],a)<dis(p[1],b);
    return (a-p[1])*(b-p[1])>0;
}
bool operator<(node a,node b)
{
	if(fabs(a.y-b.y)<eps) return a.x<b.x;
	return a.y<b.y;
}
int s[maxn],top;
void solve()
{
    for(int i=2;i<=cnt;i++) if(p[i]<p[1])swap(p[i],p[1]);
    sort(p+2,p+cnt+1,cmp);
    s[1]=1;s[2]=2;top=2;
    for(int i=3;i<=cnt;i++)
    {
        for(;top>1 && (p[s[top]]-p[s[top-1]])*(p[i]-p[s[top-1]])<=0;top--);
        top++;s[top]=i;
    }
    s[top+1]=1;
    //for(int i=1;i<=top;i++) ans+=sqrt(dis(p[s[i]],p[s[i+1]]));
}
double get(int a,int b,int c)
{
    double tmp=(p[a]-p[b])*(p[a]-p[c]);
    return fabs(tmp);
}
void rc()
{
    //printf("%d",top);
    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++)
        {
            for(;a%top+1!=y&&get(s[a],s[x],s[y])<get(s[a+1],s[x],s[y]);a=a%top+1);
            for(;b%top+1!=x&&get(s[b],s[x],s[y])<get(s[b+1],s[x],s[y]);b=b%top+1);
            ans=max(ans,get(s[a],s[x],s[y])+get(s[b],s[x],s[y]));
        }
    }
}
int main()
{
    scanf("%d",&n);cnt=n;
    for(int i=1;i<=n;i++)
    {
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    solve();
    rc();
    printf("%.3lf",ans/2);
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值