zoukankan      html  css  js  c++  java
  • [Codeforces50C]Happy Farm 5 凸包

    大致题意:

      平面上有n个整数点,问你最少经过多少步能够将所有点严格包围。

      将点严格包围要求你走的路径完全包围给出的点且不能有点在路径上

      你只能走整数点,且方向只有上下左右左上右下等8个方向,每次移动一格。

    答案

      先对点构造凸包,答案即为每条边 max(abs(x1-x2),abs(y1-y2))的累加和+4;

      

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<set>
    #include<map>
    #include<stack>
    #include<time.h>
    #include<cstdlib>
    #include<cmath>
    #include<list>
    using namespace std;
    #define MAXN 100100
    #define eps 1e-9
    #define For(i,a,b) for(int i=a;i<=b;i++) 
    #define Fore(i,a,b) for(int i=a;i>=b;i--) 
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    #define mkp make_pair
    #define pb push_back
    #define cr clear()
    #define sz size()
    #define met(a,b) memset(a,b,sizeof(a))
    #define iossy ios::sync_with_stdio(false)
    #define fre freopen
    #define pi acos(-1.0)
    #define inf 1e6+7
    #define Vector Point
    const int Mod=1e9+7;
    typedef unsigned long long ull;
    typedef long long ll;
    int dcmp(double x){
        if(fabs(x)<=eps) return 0;
        return x<0?-1:1;
    }
    struct Point{
        double x,y;
        Point(double x=0,double y=0):x(x),y(y) {}
        bool operator < (const Point &a)const{
            if(x==a.x) return y<a.y;
            return x<a.x;
        }
        Point operator - (const Point &a)const{
            return Point(x-a.x,y-a.y);
        }
        Point operator + (const Point &a)const{
            return Point(x+a.x,y+a.y);
        }
        Point operator * (const double &a)const{
            return Point(x*a,y*a);
        }
        Point operator / (const double &a)const{
            return Point(x/a,y/a);
        }
        void read(){
            scanf("%lf%lf",&x,&y);
        }
        void out(){
            cout<<"debug: "<<x<<" "<<y<<endl;
        }
        bool operator == (const Point &a)const{
            return dcmp(x-a.x)==0 && dcmp(y-a.y)==0;
        }
    };
    double Dot(Vector a,Vector b) {
        return a.x*b.x+a.y*b.y;
    }
    double dis(Vector a) {
        return sqrt(Dot(a,a));
    }
    double Cross(Point a,Point b){
        return a.x*b.y-a.y*b.x;
    }
    int ConvexHull(Point *p,int n,Point *ch){
        int m=0;
        For(i,0,n-1) {
            while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
            ch[m++]=p[i];
        }
        int k=m;
        Fore(i,n-2,0){
            while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
            ch[m++]=p[i];
        }
        if(n>1) m--;
        return m;
    }
    bool cmp(Point a,Point b){
        return a.y<b.y;
    }
    int n,m;
    Point p[100005];
    Point ch[100005];
    void solve(){
        cin>>n;
        int ans=0;
        For(i,0,n-1) p[i].read();
        sort(p,p+n);
        m=ConvexHull(p,n,ch);
        For(i,0,m-1) {
            Point tp=ch[(i+1)%m]-ch[i];
            ans+=max(abs(tp.x),abs(tp.y));
        }
        cout<<ans+4<<endl;
    }
    int main(){
    //    fre("in.txt","r",stdin);
        int t=0;
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    raid0
    GitHub 标星 11000+,阿里开源的微服务组件如何连续 10 年扛住双十一大促?
    写给大家看的“不负责任” K8s 入门文档
    快速迁移 Next.js 应用到函数计算
    轻松搭建基于 Serverless 的 Go 应用(Gin、Beego 举例)
    阿里巴巴副总裁肖力:云原生安全下看企业新边界——身份管理
    从零开始入门 K8s | K8s 安全之访问控制
    深度解读!阿里统一应用管理架构升级的教训与实践
    CNCF 2019 年度报告重磅发布 | 云原生生态周报 Vol. 41
    HTML+CSS技术实现网页滑动门效果
  • 原文地址:https://www.cnblogs.com/cjbiantai/p/9319872.html
Copyright © 2011-2022 走看看