zoukankan      html  css  js  c++  java
  • 凸包性质——cf1044C

    由题目给出的条件不难发现这是个凸包

    又因为要求的是曼哈顿距离的最大值,所以当k>=4时都是同一个答案,即上下左右的最远点构成的凸包外接矩形

    当k=3时固定两个极点,枚举第三个点即可(赋值粘贴就完事了)

    #include<bits/stdc++.h>
    using namespace std;
    #define N 300005
    #define ll long long  
    
    struct point{
        ll x,y;
    }p[N],l,r,u,d;
    int n;
    int cmp1(point &a,point &b){return a.x<b.x;}
    int cmp2(point &a,point &b){return a.x>b.x;}
    int cmp3(point &a,point &b){return a.y>b.y;}
    int cmp4(point &a,point &b){return a.y<b.y;}
    int equ(point a,point b){return a.x==b.x && a.y==b.y;}
    
    int main(){
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>p[i].x>>p[i].y;
        sort(p+1,p+1+n,cmp1);l=p[1];
        sort(p+1,p+1+n,cmp2);r=p[1];
        sort(p+1,p+1+n,cmp3);u=p[1];
        sort(p+1,p+1+n,cmp4);d=p[1];
        
        ll Max=0;
        for(int i=1;i<=n;i++){
            if(equ(p[i],l)||equ(p[i],r))continue;
            point k1=p[i],k2=l,k3=r;
            ll up=max(k1.y,max(k2.y,k3.y));
            ll down=min(k1.y,min(k2.y,k3.y));
            ll ri=max(k1.x,max(k2.x,k3.x));
            ll le=min(k1.x,min(k2.x,k3.x));
            Max=max(Max,2*(ri-le)+2*(up-down));
        }
        for(int i=1;i<=n;i++){
            if(equ(p[i],u)||equ(p[i],d))continue;
            point k1=p[i],k2=u,k3=d;
            ll up=max(k1.y,max(k2.y,k3.y));
            ll down=min(k1.y,min(k2.y,k3.y));
            ll ri=max(k1.x,max(k2.x,k3.x));
            ll le=min(k1.x,min(k2.x,k3.x));
            Max=max(Max,2*(ri-le)+2*(up-down));    
        }
        for(int i=1;i<=n;i++){
            if(equ(p[i],l)||equ(p[i],d))continue;
            point k1=p[i],k2=l,k3=d;
            ll up=max(k1.y,max(k2.y,k3.y));
            ll down=min(k1.y,min(k2.y,k3.y));
            ll ri=max(k1.x,max(k2.x,k3.x));
            ll le=min(k1.x,min(k2.x,k3.x));
            Max=max(Max,2*(ri-le)+2*(up-down));
        }
        for(int i=1;i<=n;i++){
            if(equ(p[i],l)||equ(p[i],u))continue;
            point k1=p[i],k2=l,k3=u;
            ll up=max(k1.y,max(k2.y,k3.y));
            ll down=min(k1.y,min(k2.y,k3.y));
            ll ri=max(k1.x,max(k2.x,k3.x));
            ll le=min(k1.x,min(k2.x,k3.x));
            Max=max(Max,2*(ri-le)+2*(up-down));
        }
        for(int i=1;i<=n;i++){
            if(equ(p[i],r)||equ(p[i],d))continue;
            point k1=p[i],k2=r,k3=d;
            ll up=max(k1.y,max(k2.y,k3.y));
            ll down=min(k1.y,min(k2.y,k3.y));
            ll ri=max(k1.x,max(k2.x,k3.x));
            ll le=min(k1.x,min(k2.x,k3.x));
            Max=max(Max,2*(ri-le)+2*(up-down));
        }
        for(int i=1;i<=n;i++){
            if(equ(p[i],r)||equ(p[i],u))continue;
            point k1=p[i],k2=r,k3=u;
            ll up=max(k1.y,max(k2.y,k3.y));
            ll down=min(k1.y,min(k2.y,k3.y));
            ll ri=max(k1.x,max(k2.x,k3.x));
            ll le=min(k1.x,min(k2.x,k3.x));
            Max=max(Max,2*(ri-le)+2*(up-down));
        }
    
        cout<<Max<<" ";
        for(int i=4;i<=n;i++)
            cout<<2*(u.y-d.y)+2*(r.x-l.x)<<" ";
    } 
  • 相关阅读:
    PHP原生实现,校验微信公众号||小程序服务器地址
    TP3.2校验微信公众号||小程序 服务器地址
    【微信小程序】解决 竖向<scroll-view>组件 “竖向滚动页面出现遮挡”问题
    【微信小程序】:confirm(删除提示)
    【微信小程序】:评论、回复和删除功能 -- 2017/7/14
    微信小程序:bindtap方法传参
    TP3.2之WHERE组合条件处理
    Python:导入numpy报错 No module named numpy
    Python: 二进制、八进制、十六进制转换或者输出
    Python:数字的格式化输出
  • 原文地址:https://www.cnblogs.com/zsben991126/p/12535463.html
Copyright © 2011-2022 走看看