zoukankan      html  css  js  c++  java
  • poj 2187 Beauty Contest 最远点距

    /**
    求出凸包枚举每个点的矩距离即可  因为凸包上的点可定不多。。
    学习: 刚开始WA 了一次,,因为用int 存的, 一看discuss 里提供的数据,想起来,,应该是越界了。。
    后来用longlong 就过了。。
    **/
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    
    struct point {
        long long  x,y;
        //point (){}
        point (double x=0,double y=0):x(x),y(y){}
    };
    point p[50050],ch[50050];
    
    typedef point Vector;
    
    Vector operator -(point a,point b){
        return Vector (a.x-b.x,a.y-b.y);
    }
    long long  cross(Vector a,Vector b){
        return a.x*b.y-a.y*b.x;
    }
    
    bool cmp(point a,point b){
        if(a.x==b.x)
            return a.y<b.y;
        return a.x<b.x;
    }
    long long  length(Vector a){
        return a.x*a.x+a.y*a.y;
    }
    
    int convexHull(point *p,int n,point *ch){
        sort(p,p+n,cmp);
        int m =0;
        for(int i=0;i<n;i++){
            while(m>1&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
                m--;
            ch[m++] = p[i];
        }
        int k = m;
        for(int i=n-2;i>=0;i--){
            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;
    }
    
    int main()
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>p[i].x>>p[i].y;
        }
        int m = convexHull(p,n,ch);
        long long  max_len = 0;
        for(int i=0;i<m;i++){
            for(int j=i+1;j<m;j++){
                if(length(ch[j]-ch[i])>max_len)
                    max_len = length(ch[j]-ch[i]);
            }
        }
        cout<<max_len<<endl;
        return 0;
    }
  • 相关阅读:
    GIT
    curl
    排序算法
    《软件设计师》考点分布
    lua第三方库
    WordPress
    go http
    Unity UI相关总结
    note
    LUA重难点解析
  • 原文地址:https://www.cnblogs.com/Bang-cansee/p/3724174.html
Copyright © 2011-2022 走看看