zoukankan      html  css  js  c++  java
  • poj 1113 Wall 凸包

    Wall
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 25770   Accepted: 8575

    Description

    Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall. 

    Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements. 

    The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.

    Input

    The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle. 

    Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.

    Output

    Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.

    Sample Input

    9 100
    200 400
    300 400
    300 300
    400 300
    400 400
    500 400
    500 200
    350 200
    200 200

    Sample Output

    1628

    Hint

    结果四舍五入就可以了

    Source



    ---------

    求凸包,凸多边形的周长+以L为半径的圆的周长

    ---------

    #include<vector>
    #include<list>
    #include<map>
    #include<set>
    #include<deque>
    #include<queue>
    #include<stack>
    #include<bitset>
    #include<algorithm>
    #include<functional>
    #include<numeric>
    #include<utility>
    #include<iostream>
    #include<sstream>
    #include<iomanip>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cctype>
    #include<string>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    #include<climits>
    #include<complex>
    #define mp make_pair
    #define pb push_back
    using namespace std;
    const double eps=1e-8;
    const double pi=acos(-1.0);
    const double inf=1e20;
    const int maxp=1111;
    int dblcmp(double d)
    {
        if (fabs(d)<eps)return 0;
        return d>eps?1:-1;
    }
    inline double sqr(double x){return x*x;}
    
    struct point
    {
        double x,y;
        point(){}
        point(double _x,double _y):
        x(_x),y(_y){};
        void input()
        {
            scanf("%lf%lf",&x,&y);
        }
        void output()
        {
            printf("%.2f %.2f\n",x,y);
        }
        bool operator==(point a)const
        {
            return dblcmp(a.x-x)==0&&dblcmp(a.y-y)==0;
        }
        bool operator<(point a)const
        {
            return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:x<a.x;
        }
        double len()
        {
            return hypot(x,y);
        }
        double len2()
        {
            return x*x+y*y;
        }
        double distance(point p)
        {
            return hypot(x-p.x,y-p.y);
        }
        point add(point p)
        {
            return point(x+p.x,y+p.y);
        }
        point sub(point p)
        {
            return point(x-p.x,y-p.y);
        }
        point mul(double b)
        {
            return point(x*b,y*b);
        }
        point div(double b)
        {
            return point(x/b,y/b);
        }
        double dot(point p)
        {
            return x*p.x+y*p.y;
        }
        double det(point p)
        {
            return x*p.y-y*p.x;
        }
    };
    struct polygon
    {
        int n;
        point p[maxp];
        void input(int _n)
        {
            n=_n;
            for (int i=0;i<n;i++)
            {
                p[i].input();
            }
        }
        void add(point q)
        {
            p[n++]=q;
        }
        struct cmp
        {
            point p;
            cmp(const point &p0){p=p0;}
            bool operator()(const point &aa,const point &bb)
            {
                point a=aa,b=bb;
                int d=dblcmp(a.sub(p).det(b.sub(p)));
                if (d==0)
                {
                    return dblcmp(a.distance(p)-b.distance(p))<0;
                }
                return d>0;
            }
        };
        void getconvex(polygon &convex)
        {
            int i,j,k;
            sort(p,p+n);
            convex.n=n;
            for (i=0;i<min(n,2);i++)
            {
                convex.p[i]=p[i];
            }
            if (n<=2)return;
            int &top=convex.n;
            top=1;
            for (i=2;i<n;i++)
            {
                while (top&&convex.p[top].sub(p[i]).det(convex.p[top-1].sub(p[i]))<=0)
                    top--;
                convex.p[++top]=p[i];
            }
            int temp=top;
            convex.p[++top]=p[n-2];
            for (i=n-3;i>=0;i--)
            {
                while (top!=temp&&convex.p[top].sub(p[i]).det(convex.p[top-1].sub(p[i]))<=0)
                    top--;
                convex.p[++top]=p[i];
            }
        }
        double getcircumference()
        {
            double sum=0;
            int i;
            for (i=0;i<n;i++)
            {
                sum+=p[i].distance(p[(i+1)%n]);
            }
            return sum;
        }
    };
    int n;
    int L;
    int main()
    {
        while (~scanf("%d%d",&n,&L))
        {
            polygon a,b;
            a.input(n);
            a.getconvex(b);
            double ans=b.getcircumference()+2.0*pi*L;
            printf("%0.0f\n",ans);
        }
        return 0;
    }
    






  • 相关阅读:
    网址
    123
    工具安装
    博客专栏-计算机网络
    JQuery(1)
    HTML常用标签
    Spring的线程池技术:ThreadPoolTaskExecutor
    Error:java: 程序包lombok不存在- IDEA+maven+lombok
    Andriod Studio中新创建的xml布局文件无法在R.layout中调用
    SAST : Single-Shot Arbitrarily-Shaped Text Detector论文阅读笔记
  • 原文地址:https://www.cnblogs.com/cyendra/p/3226292.html
Copyright © 2011-2022 走看看