zoukankan      html  css  js  c++  java
  • poj

    题意:顺时针方向给出N个点,求外围距离这些点L距离的点围成的图形的周长,结果四舍五入到整数(3 <= N <= 1000,1 <= L <= 1000,-10000 <= Xi, Yi <= 10000) 。

    题目链接:http://poj.org/problem?id=1113

    ——>>先求凸包,然后求凸包的周长加上一个半径为L的圆的周长。

    注意:用round()四舍五入后,若用%.0lf输出会WA,round()后强转为int后输出AC!

    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    
    using namespace std;
    
    const int maxn = 1000 + 10;
    const double eps = 1e-10;
    const double pi = acos(-1);
    
    int dcmp(double x){
        if(fabs(x) < eps) return 0;
        else return x < 0 ? -1 : 1;
    }
    
    struct Point{
        double x;
        double y;
        Point(double x = 0, double y = 0):x(x), y(y){}
        bool operator < (const Point& e) const{
            return x < e.x || (dcmp(x - e.x) == 0 && y < e.y);
        }
    }p[maxn], q[maxn];
    
    typedef Point Vector;
    
    Vector operator + (Point A, Point B){
        return Vector(A.x + B.x, A.y + B.y);
    }
    
    Vector operator - (Point A, Point B){
        return Vector(A.x - B.x, A.y - B.y);
    }
    
    Vector operator * (Point A, double p){
        return Vector(A.x * p, A.y * p);
    }
    
    Vector operator / (Point A, double p){
        return Vector(A.x / p, A.y / p);
    }
    
    double Cross(Vector A, Vector B){
        return A.x * B.y - B.x * A.y;
    }
    
    int ConvexHull(Point *p, int n, Point* ch){        //求凸包
        sort(p, p + n);
        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;
    }
    
    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()
    {
        int N, L;
        while(scanf("%d%d", &N, &L) == 2){
            for(int i = 0; i < N; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
            double ret = 0;
            int m = ConvexHull(p, N, q);
            for(int i = 1; i < m; i++) ret += Dis(q[i], q[i-1]);
            ret += Dis(q[0], q[m-1]) + 2 * pi * L;
            int ans = round(ret);
            printf("%d
    ", ans);
        }
        return 0;
    }
    


  • 相关阅读:
    Extjs打开window窗口自动加载html网页
    CSS预处理器之SASS用法指南
    HmacSHA256摘要算法
    Base64编解码
    孔子困于陈蔡故事(转载)
    我的2019
    给Oracle字段和表加注释
    【JDBC】使用properties连Oracle数据库,使用DatabaseMetaData获取字段的注释
    [JDBC]查询结果集把字段名和字段值一起竖向输出
    [Java/Reflect]使用反射机制获得一个对象的属性名和属性值
  • 原文地址:https://www.cnblogs.com/riskyer/p/3331434.html
Copyright © 2011-2022 走看看