• POJ-1113 Wall


    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
    结果四舍五入就可以了
    先求城墙的凸包
    外面围墙的直线部分与城墙的凸包长相同
    再求凸包的顶点的弧线长和:注意每段弧长对应的角与凸包该点内角互补(另两个角为直角),所以所有弧度角和为(180-内角)和,即(180*n-(n-2)*180)(n为凸包边数,(n-2)*180为凸包内角和),即2*180,正好是一个圆。
    所以,最后总长为 凸包边长+2*3.141592653*len(len为已知与城堡的最远距离)
      注意四舍五入,注意PI的精度要高!
    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #include<math.h>
    using namespace std;
    struct T
    {
        int x,y;
    }t[1000],p[1000];
    int dis(T a,T b)
    {
        return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
    }
    int m(T a,T b,T c)
    {
        return  (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
    }
    int cmp(T a,T b)
    {
        int x=m(a,b,t[0]);
        if(x>0||(x==0&&dis(b,t[0])>dis(a,t[0])))
            return 1;
        return 0;
    }
    int main()
    {
        int w,n;
        while(~scanf("%d%d",&n,&w))
        {
            int k=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d%d",&t[i].x,&t[i].y);
                if(t[i].y<t[k].y||(t[i].y==t[k].y&&t[i].x<t[k].x))
                    k=i;
            }
            swap(t[k],t[0]);
            sort(t+1,t+n,cmp);
            int top=2;
            p[0]=t[0];
            p[1]=t[1];
            for(int i=2;i<n;i++)
            {
                while(top>1&&m(p[top-1],p[top-2],t[i])>=0)top--;
                p[top++]=t[i];
            }
            p[top]=p[0];
            double ans=0;
            for(int i=0;i<top;i++)
            {
                ans+=sqrt(dis(p[i],p[i+1]));
            }
            ans+=2*3.141592653*w;
            printf("%.0f
    ",ans);
        }
    }

  • 相关阅读:
    NFS /etc/exports参数解释
    M3U8流视频数据爬虫
    Qt5之C++Widgets编程
    Qt Quick
    RabbitMQ 安装配置
    nginx和netty区别
    S锁和X锁
    关于Spring Cloud各种组件的停更/升级/替换
    3、无重复字符的最长子串
    Spring Cloud Alibaba Sentinel实现熔断与限流
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053365.html
Copyright © 2020-2023  润新知