# POJ-1113-Wall（凸包）

//FS
//#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define MAXM 100005
const double eps = 1e-8;
const double PI = acos(-1.0);
const long long mod=1e9+7;
const int MAXN = 2007;
int sgn(double x)
{
if(fabs(x)<eps)return 0;
if(x<0)return -1;
return 1;
}
struct Point
{
double x,y;
Point(){}
Point(double _x, double _y){x=_x,y=_y;}
bool operator <(Point b)const
{
return sgn(x-b.x)==0? sgn(y-b.y)<0:x<b.x;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const //叉积
{
return x*b.y-b.x*y;
}
double dist(Point p)
{
return hypot(x-p.x,y-p.y);
}
double len()
{
return hypot(x,y);
}
};
Point List[MAXN];
int Stack[MAXN],top;
bool cmp(Point p1, Point p2)
{
double temp = (p1-List[0])^(p2-List[0]);
if(sgn(temp)>0)return 1;
if(sgn(temp)==0 && List[0].dist(p1)<=List[0].dist(p2))return 1;
return 0;
}
void Graham(int n)
{
Point p;
int k=0;
p=List[0];
for(int i=1; i<n; ++i)
if( (p.y>List[i].y) || (p.y==List[i].y && p.x>List[i].x))
{
p=List[i];
k=i;
}
swap(List[k],List[0]);
sort(List+1,List+n,cmp);
Stack[0]=0;
top=1;
if(n==1)return;
Stack[1]=1;
top=2;
if(n==2)return ;
for(int i=2; i<n; ++i)
{
while(top>1 && sgn( (List[ Stack[top-1] ]-List[ Stack[top-2] ])^(List[i]-List[ Stack[top-2] ]))<=0)
top--;
Stack[top++]=i;
}
}
int main()
{
int n,l;
while(scanf("%d%d",&n,&l)!=EOF)
{
for(int i=0; i<n; ++i)
scanf("%lf%lf",&List[i].x,&List[i].y);
Graham(n);
double ans=0;
for(int i=1; i<top; ++i)
ans+=List[Stack[i]].dist( List[Stack[i-1]] );
ans+=List[Stack[0]].dist(List[Stack[top-1]]);
ans+=2.0*PI*l;
printf("%d\n", (int)(ans+0.5));
}
return 0;
}
/*
9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200
*/

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客