[BZOJ1069][SCOI2007]最大土地面积(计算几何-旋转卡壳-最远点对)

题目:

我是超链接

题解:

有了上个题的基础我们就知道怎么做了吧,这里有四个点,看看数据范围,我们枚举对角线就可以了,求两侧最大三角形
O(n2) 此题卡常。

代码:

#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const double INF=1e18;
const double eps=1e-9;
int dcmp(double x)
{
    if (x<=eps && x>=-eps) return 0;
    return (x>0)?1:-1;
}
struct po
{
    double x,y;
    po (double X=0,double Y=0){x=X; y=Y;}
}d[50005],sta[50005];
int n,top;double ans;
bool operator <(const po &a,const po&b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
double cj(po x,po y){return x.x*y.y-x.y*y.x;}
po operator -(po x,po y){return po(x.x-y.x,x.y-y.y);}
void tb()
{
    sort(d+1,d+n+1);
    top=0;
    for (int i=1;i<=n;i++)
    {
        while (top>1 && dcmp(cj(sta[top]-sta[top-1],d[i]-sta[top-1]))<=0) top--;
        sta[++top]=d[i];     
    }
    int k=top;
    for (int i=n-1;i>=1;i--)
    {
        while (top>k && dcmp(cj(sta[top]-sta[top-1],d[i]-sta[top-1]))<=0) top--;
        sta[++top]=d[i];
    }
    if (n>1) top--;
}
void rotating()
{
    int j,k,l;
    sta[top+1]=sta[1];
    for (int i=1;i<=top;i++)
    {
        k=i+1;l=(i+2)%top+1; //
        for (int j=i+2;j<=top;j++)
          {
            double ans1=0;
            while (k%top+1<j && dcmp(cj(sta[k]-sta[i],sta[j]-sta[i]) - cj(sta[k+1]-sta[i],sta[j]-sta[i]))<0) k=k%top+1;
            ans1+=cj(sta[k]-sta[i],sta[j]-sta[i])/2;

            while (dcmp(cj(sta[j]-sta[i],sta[l]-sta[i]) - cj(sta[j]-sta[i],sta[l+1]-sta[i]))<0) l=l%top+1;
            ans1+=cj(sta[j]-sta[i],sta[l]-sta[i])/2;
            ans=max(ans,ans1);
          }
    }
}
int main()
{
    double x,y;ans=-INF;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%lf%lf",&x,&y);
        d[i]=po(x,y);
    }
    tb();
    rotating();
    printf("%.3lf\n",ans);
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值