BZOJ 1069 [SCOI2007]最大土地面积

Description

  在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成
的多边形面积最大。


【题目分析】
好神奇的一道题目,首先肯定的是这四个点是凸包上的点。然后枚举肯定会T,所以可以枚举对角线。然后可以发现更新的时候答案是单调的。然后用旋转卡壳的方法跑一边就可以了。其实是看了Aaron Polaris的题解和标程


【代码】

#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <stack>
#include <cmath>
using namespace std;
struct P{
    double x,y;
}p[2001];
P s[2001];
int top=0;
double ans;
inline double dcmp(double a)
{
    if (fabs(a)<=1e-8) return 0;
    else return a>0?1:-1;
}
inline double dis(P a,P b)
{return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
inline P operator - (P a,P b)
{return (P){a.x-b.x,a.y-b.y};}
inline double operator * (P a,P b)
{return a.x*b.y-a.y*b.x;}
inline bool operator<(P a,P b)
{
    int x=dcmp((p[1]-a)*(p[1]-b));
    if (x==0) return dis(p[1],a)<dis(p[1],b);
    else return x>0;
}
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%lf%lf",&p[i].x,&p[i].y);
    int t=1;
    for (int i=2;i<=n;++i) if (p[i].y<p[t].y||(p[i].y==p[t].y&&p[i].x<p[t].x)) t=i;//扫描一遍,找到起始点 
    swap(p[1],p[t]);
    sort(p+2,p+n+1);
    s[++top]=p[1];s[++top]=p[2];
    for (int i=3;i<=n;++i)
    {
        while (top>1&&dcmp((p[i]-s[top-1])*(s[top]-s[top-1]))>=0) top--;//刚开始这里乘反了,结果怎么都是0,找了好久才找到
        s[++top]=p[i];
    }
    s[top+1]=s[1];
    int a,b;
    for (int x=1;x<top-1;++x)
    {
        a=x%top+1;b=(x+2)%top+1;
        for (int y=x+2;y<=top;++y)
        {
            while (a%top+1!=y&&dcmp((s[a+1]-s[x])*(s[y]-s[x])-(s[a]-s[x])*(s[y]-s[x]))>0) a=a%top+1; 
            while (b%top+1!=x&&dcmp((s[y]-s[x])*(s[b+1]-s[x])-(s[y]-s[x])*(s[b]-s[x]))>0) b=b%top+1;
            ans=max(ans,(s[a]-s[x])*(s[y]-s[x])+(s[y]-s[x])*(s[b]-s[x]));
        }
    }
    printf("%.3lf\n",ans/2.0);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值