poj 1113Wall

http://poj.org/problem?id=1113

 1 #include<cstdio>

 2 #include<cstring>

 3 #include<cstdlib>

 4 #include<cmath>

 5 #include<algorithm>

 6 using namespace std;

 7 

 8 const int maxn=5000;

 9 const double pi=acos(-1.0);

10 

11 struct point

12 {

13     double x,y;

14     bool operator <(const point &a)const

15     {

16         return (x<a.x)||(x==a.x&&y<a.y);

17     }

18 }p[maxn],ch[maxn];

19 

20 double sqr(double x)

21 {

22     return x*x;

23 }

24 

25 double det(point a,point b,point c)

26 {

27     return ((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));

28 }

29 

30 double dis(point a,point b)

31 {

32     return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));

33 }

34 

35 int convex_hull(point *p,int n,point *ch)

36 {

37     sort(p,p+n);

38     int m=0;

39     for(int i=0; i<n; i++)

40     {

41         while(m>1&&det(ch[m-2],ch[m-1],p[i])<=0) m--;

42         ch[m++]=p[i];

43     }

44     int k=m;

45     for(int i=n-2; i>=0; i--)

46     {

47         while(m>k&&det(ch[m-2],ch[m-1],p[i])<=0) m--;

48         ch[m++]=p[i];

49     }

50     if(n>1) m--;

51     return m;

52 }

53 

54 double diss(point *ch,int n)

55 {

56     double sum=0;

57     for(int i=1; i<n; i++)

58     {

59         sum+=dis(ch[i],ch[i-1]);

60     }

61     return sum;

62 }

63 int main()

64 {

65     int n,l;

66     scanf("%d%d",&n,&l);

67     for(int i=0; i<n; i++)

68     {

69         scanf("%lf%lf",&p[i].x,&p[i].y);

70     }

71     int cn=convex_hull(p,n,ch);

72     printf("%.lf\n",(diss(ch,cn+1)+2*pi*l));

73     return 0;

74 }
View Code

 

你可能感兴趣的:(poj)