题意:给一些点,用一个多边形把这些点包起来,并且所有点到边的距离至少为L
思路:先求一个凸包然后再加上一个圆的弧长,为什么加圆的弧长呢?可以证明每个顶点到他距离为L的点组成了一个圆弧,过该点做两条垂线可以证明所有点的这些圆弧这些角度加起来正好360度是一个圆,所有就加上一个半径为L的圆
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
struct Point
{
double x,y;
Point(double x = 0,double y = 0) : x(x),y(y) {}
};
typedef Point Vector;
Vector operator + (Vector a,Vector b) { return Vector(a.x+b.x,a.y+b.y) ;}
Vector operator - (Vector a,Vector b) { return Vector(a.x-b.x,a.y-b.y) ;}
Vector operator * (Vector a,double p) { return Vector(a.x*p,a.y*p) ;}
Vector operator / (Vector a,double p) { return Vector(a.x/p,a.y/p) ;}
const double eps = 1e-9;
const double PI = acos(-1.0);
double Dot(Vector a,Vector b) { return a.x*b.x + a.y*b.y ;}
double Length(Vector a) { return sqrt(Dot(a,a)) ;}
double Cross(Vector a,Vector b) { return a.x*b.y - a.y*b.x ;}
int dcmp(double x)
{
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
bool operator < (Point a,Point b) { return a.x < b.x || (a.x == b.x && a.y < b.y) ;}
bool operator == ( Point a, Point b) { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0 ;}
double Angle(Vector a,Vector b) { return acos( Dot(a,b) / Length(a) / Length(b) ) ;}
double Area(Point a,Point b,Point c) { return fabs(Cross(b-a,c-a))/2 ;}
Vector Rotate(Vector a,double rad) { return Vector(a.x*cos(rad) - a.y*sin(rad),a.x*sin(rad) + a.y*cos(rad) );}
Vector Normal(Vector a)
{
double L = Length(a);
return Vector(-a.y/L,a.x/L);
}
Point GetLineIntersection(Point p,Vector v,Point q,Vector w)
{
Vector u = p - q;
double t = Cross(w,u) / Cross(v,w);
return p + v*t;
}
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
double c1 = Cross(a2-a1,b1-a1) ,c2 = Cross(a2-a1,b2-a1),c3 = Cross(b2-b1,a1-b1),c4 = Cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3) *dcmp(c3) < 0;
}
bool OnSengment(Point p,Point a,Point b)
{
return dcmp(Cross(p-a,b-a)) == 0 && dcmp(Dot(a-p,b-p) < 0);
}
double PolyArea(Point *p,int n)
{
double area = 0;
int i;
for(i = 0; i < n; i++)
{
area += Cross(p[i]-p[0],p[i+1]-p[0]);
}
return area/2;
}
struct Line
{
Point s,e;
};
int ConvexHull(Point* p,int n,Point* ch)
{
sort(p,p+n);
int m = 0;
for(int i = 0; i < n; i++)
{
while( m > 1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--;
ch[m++] = p[i];
}
int k = m;
for(int i = n-2 ; i >= 0; i--)
{
while(m > k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--;
ch[m++] = p[i];
}
if(n > 1) m--;
return m;
}
Point p[1005];
int main()
{
int n,L;
while(scanf("%d%d",&n,&L) != EOF)
{
for(int i = 0; i < n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
Point ch[1005];
int m = ConvexHull(p,n,ch);
double ans = 0;
for(int i = 0; i < m; i++)
{
ans += Length(ch[i]-ch[(i+1)%n]);
}
ans = ans + 2*PI * L;
printf("%.0lf\n",ans);
}
return 0;
}