• poj 1113 Wall 凸包


    Wall

    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 28112   Accepted: 9383

    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

    结果四舍五入就可以了
     
     
    1.求n个点的外围周长,满足,外围墙至少离n个点L的距离。式子等于  凸包周长+2*pi*L 
    周长,重点和平行点都没有关系。
     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<cmath>
     6 #include<algorithm>
     7 using namespace std;
     8 const double pi = acos(-1.0);
     9 
    10 struct node
    11 {
    12     int x,y;
    13 };
    14 node a[1002],stack1[1002];
    15 
    16 double dis(node n1,node n2)
    17 {
    18     return (double)sqrt( (n1.x-n2.x)*(n1.x-n2.x)*1.0 + (n1.y-n2.y)*(n1.y-n2.y)*1.0 );
    19 }
    20 double cross(node a,node n1,node n2)
    21 {
    22     return (n1.x-a.x)*(n2.y-a.y) - (n1.y-a.y)*(n2.x-a.x);
    23 }
    24 bool cmp(node n1,node n2)
    25 {
    26     double k = cross(a[0],n1,n2);
    27     if( k>0) return true;
    28     else if( k==0 && dis(a[0],n1)<dis(a[0],n2))
    29         return true;
    30     else return false;
    31 }
    32 double  Graham(int n)
    33 {
    34     int i,head;
    35     double r=0;
    36     for(i=1;i<n;i++)
    37         if(a[i].x<a[0].x ||(a[i].x==a[0].x&&a[i].y<a[0].y ) )
    38             swap(a[0],a[i]);
    39     sort(a+1,a+n,cmp);
    40     a[n]=a[0];
    41     stack1[0]=a[0];
    42     stack1[1]=a[1];
    43     stack1[2]=a[2];
    44     head=2;
    45     for(i=3;i<=n;i++)
    46     {
    47         while( head>=2 && cross(stack1[head-1],stack1[head],a[i])<=0 )head--;
    48         stack1[++head]=a[i];
    49     }
    50     for(i=0;i<head;i++)
    51     {
    52         r=r+dis(stack1[i],stack1[i+1]);
    53     }
    54     return r;
    55 }
    56 int main()
    57 {
    58     int n,L,i;
    59     double ans;
    60    while(scanf("%d%d",&n,&L)>0)
    61     {
    62         for(i=0;i<n;i++)
    63             scanf("%d%d",&a[i].x,&a[i].y);
    64         ans=Graham(n);
    65         ans=ans+2*pi*L;
    66         printf("%.0lf
    ",ans);
    67     }
    68     return 0;
    69 }
  • 相关阅读:
    mongodb的账户管理
    mongo备份与恢复
    mongo索引
    聚合aggregate
    07-【jsp基本了解】
    Servlet登录小案例
    06-【servletconfig、servletContext 】
    05-【session、cookie】
    jQuery
    04-【servlet转发和重定向】
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3578928.html
Copyright © 2020-2023  润新知