zoukankan      html  css  js  c++  java
  • HDU1392 Surround the Trees

    凸包

    水一下。。构造凸包求周长。。

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define full(a, b) memset(a, b, sizeof a)
    #define FAST_IO ios::sync_with_stdio(false)
    using namespace std;
    typedef long long LL;
    inline int lowbit(int x){ return x & (-x); }
    inline int read(){
        int ret = 0, w = 0; char ch = 0;
        while(!isdigit(ch)){
            w |= ch == '-', ch = getchar();
        }
        while(isdigit(ch)){
            ret = (ret << 3) + (ret << 1) + (ch ^ 48);
            ch = getchar();
        }
        return w ? -ret : ret;
    }
    inline int lcm(int a, int b){ return a / __gcd(a, b) * b; }
    template <typename A, typename B, typename C>
    inline A fpow(A x, B p, C lyd){
        A ans = 1;
        for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
        return ans;
    }
    #define eps 1e-6;
    struct Point{
        double x, y;
        Point(double x, double y): x(x), y(y){}
        Point operator + (Point &a){
            return Point(x + a.x, y + a.y);
        }
        Point operator - (Point &a){
            return Point(x - a.x, y - a.y);
        }
        bool operator < (const Point &a) const {
            if(x == a.x) return y < a.y;
            return x < a.x;
        }
        bool operator == (Point &a){
            if(x == a.x && y == a.y) return true;
            return false;
        }
        double abs(){
            return sqrt(x * x + y * y);
        }
    };
    
    typedef Point Vector;
    vector<Point> p, u, l;
    int n;
    
    double cross(Vector a, Vector b){
        return a.x * b.y - a.y * b.x;
    }
    
    bool isClock(Point a, Point b, Point c){
        Vector x = b - a;
        Vector y = c - a;
        return cross(x, y) < eps;
    }
    
    double dis(Point a, Point b){
        return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));;
    }
    
    int main(){
    
        while(~scanf("%d", &n) && n){
            p.clear(), u.clear(), l.clear();
            for(int i = 1; i <= n; i ++){
                double x, y;
                scanf("%lf%lf", &x, &y);
                p.push_back(Point(x, y));
            }
            if(n == 1){
                printf("0.00
    ");
                continue;
            }
            if(n == 2){
                printf("%.2lf
    ", dis(p[0], p[1]));
                continue;
            }
            sort(p.begin(), p.end());
            u.push_back(p[0]), u.push_back(p[1]);
            for(int i = 2; i < p.size(); i ++){
                for(int n = u.size(); n >= 2 && (!isClock(u[n - 2], u[n - 1], p[i])); n --)
                    u.pop_back();
                u.push_back(p[i]);
            }
            l.push_back(p[p.size() - 1]), l.push_back(p[p.size() - 2]);
            for(int i = p.size() - 3; i >= 0; i --){
                for(int n = l.size(); n >= 2 && (!isClock(l[n - 2], l[n - 1], p[i])); n --)
                    l.pop_back();
                l.push_back(p[i]);
            }
            for(int i = 1; i < u.size() - 1; i ++){
                l.push_back(u[i]);
            }
            double ans = 0;
            for(int i = 1; i < l.size(); i ++){
                ans += dis(l[i], l[i - 1]);
            }
            ans += dis(l[0], l[l.size() - 1]);
            printf("%.2lf
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    SAP基础:定位点运算
    WDA基础十七:ALV不同行显示不同下拉
    WDA基础十六:ALV的颜色
    WEB UI基础八:链接跳转到标准的工单界面
    WDA基础十五:POPUP WINDOW
    CRM创建BP(END USER)
    CRM 员工创建并分配用户
    STRANS一:简单的XML转换
    WEB UI 上传URL附件(使用方法备份)
    FPM四:用OVP做查询跳转到明细
  • 原文地址:https://www.cnblogs.com/onionQAQ/p/11242619.html
Copyright © 2011-2022 走看看