BZOJ1069 SCOI2007 最大土地面积 凸包、旋转卡壳

传送门


在这里假设可以选择两个相同的点吧……

那么选出来的四个点一定会在凸包上

建立凸包,然后枚举这个四边形的对角线。策略是先枚举对角线上的一个点,然后沿着凸包枚举另一个点。在枚举另一个点的过程中可以使用旋转卡壳找到在对角线两侧、距离对角线最远的两个点,这样的四个点就可以贡献答案。总时间复杂度\(O(n^2)\)

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<vector>
#include<cmath>
//This code is written by Itst
using namespace std;

#define ld long double
#define eps 1e-9
#define nxt(x) ((x) % cnt + 1)
bool cmp(ld a , ld b){
    return a + eps > b && a - eps < b;
}
struct comp{
    ld x , y;
    comp(ld _x = 0 , ld _y = 0) : x(_x) , y(_y){}
    comp operator -(comp a){
        return comp(x - a.x , y - a.y);
    }
    bool operator <(const comp a)const{
        return x < a.x || cmp(x , a.x) && y < a.y;
    }
}now[2010];
int st[2010] , ind[2010];
int top , N , cnt;

inline ld dot(comp a , comp b){
    return a.x * b.y - a.y * b.x;
}

inline ld calcS(comp a , comp b , comp c){
    return fabs(dot(b - a , c - a)) / 2;
}

void init(){
    for(int i = 1 ; i <= N ; ++i){
        while(top >= 2 && dot(now[i] - now[st[top]] , now[st[top]] - now[st[top - 1]]) > -eps)
            --top;
        st[++top] = i;
    }
    for(int i = 1 ; i <= top ; ++i)
        ind[++cnt] = st[i];
    top = 0;
    for(int i = N ; i ; --i){
        while(top >= 2 && dot(now[i] - now[st[top]] , now[st[top]] - now[st[top - 1]]) > -eps)
            --top;
        st[++top] = i;
    }
    for(int i = 2 ; i < top ; ++i)
        ind[++cnt] = st[i];
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
    //freopen("out","w",stdout);
#endif
    scanf("%d" , &N);
    for(int i = 1 ; i <= N ; ++i)
        scanf("%Lf %Lf" , &now[i].x , &now[i].y);
    sort(now + 1 , now + N + 1);
    init();
    if(cnt == 3)
        cout << fixed << setprecision(3) << calcS(now[st[1]] , now[st[2]] , now[st[3]]);
    else{
        ld ans = 0;
        for(int i = 1 ; i <= cnt ; ++i){
            int p = i , q = nxt(nxt(i));
            for(int j = nxt(nxt(i)) ; nxt(j) != i ; j = nxt(j)){
                while(calcS(now[ind[p]] , now[ind[i]] , now[ind[j]]) < calcS(now[ind[nxt(p)]] , now[ind[i]] , now[ind[j]]))
                    p = nxt(p);
                while(calcS(now[ind[q]] , now[ind[i]] , now[ind[j]]) < calcS(now[ind[nxt(q)]] , now[ind[i]] , now[ind[j]]))
                    q = nxt(q);
                ans = max(ans , calcS(now[ind[p]] , now[ind[i]] , now[ind[j]]) + calcS(now[ind[q]] , now[ind[i]] , now[ind[j]]));
            }
        }
        cout << fixed << setprecision(3) << ans;
    }
    return 0;
}

转载于:https://www.cnblogs.com/Itst/p/10338949.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值