求凸包 最后加上一个圆的周长即可
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstring>
#include<cmath>
#define fabs(x) ((x) < 0 ? (-(x)) : (x))
#define SF scanf
#define PF printf
using namespace std;
typedef long long LL;
const int MAXN = 1000;
const int INF = 1234567890;
const double L = 100000.0;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct Vector {
double x, y;
Vector () {}
Vector (double xx, double yy) { x = xx; y = yy; }
Vector (double rad) { x = cos(rad); y = sin(rad); }
double len() const { return sqrt(x*x + y*y); }
Vector operator + (const Vector &b) const {
return Vector(x + b.x, y + b.y);
}
Vector operator - (const Vector &b) const {
return Vector(x - b.x, y - b.y);
}
Vector operator * (const double &b) const {
return Vector(x * b, y * b);
}
Vector operator / (const double &b) const {
return Vector(x / b, y / b);
}
bool operator < (const Vector &b) const {
return (x < b.x || (x == b.x && y < b.y));
}
};
typedef Vector Point, Angle;
struct Line {
Point P;
Vector v;
double ang;
Line () {}
Line (Point A, Vector B) : P(A), v(B) { ang = atan2(v.y, v.x); }
bool operator < (const Line &L) const {
return ang < L.ang;
}
};
double Dot(const Vector &a, const Vector &b) {
return a.x * b.x + a.y * b.y;
}
double Cross(const Vector &a, const Vector &b) {
return a.x * b.y - a.y * b.x;
}
Vector GetAngle(const Vector &a, const Vector &b) {
double l1 = a.len(), l2 = b.len();
return Vector(Dot(a, b) / l1 / l2, Cross(a, b)/ l1 / l2);
}
Vector Rotate(const Vector &a, const Angle &angle) {
return Vector(a.x * angle.x - a.y * angle.y, a.x * angle.y + a.y * angle.x);
}
Point GetIntersection(const Point &a, const Point &b, const Point &c, const Point &d)
{
double t = 1.0 * Cross(d - c, a - c) / Cross(b - a, d - c);
return a + (b - a) * t;
}
Point GetIntersection(const Line &a, const Line &b)
{
Vector u = a.P - b.P;
double t = Cross(b.v, u) / Cross(a.v, b.v);
return a.P + a.v * t;
}
int GetDirection(const Point &a, const Point &b, const Point &c)
{
// -1 逆时针
Vector v = b - a, B = c - a;
double flag = Cross(B, v);
if(flag < 0) return -1; if(flag > 0) return 1; return 0;
}
double GetDis(Point &a, Point &b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool OnLeft(Line L, Point P) {
return Cross(L.v, P-L.P) > 0;
}
bool HalfPlaneIntersection(Line *L, int N, Point *Ans)
{
sort(L, L+N);
int F, R;
Point *p = new Point[N]; // p[i]为q[i+1]和q[i]的交点
Line *q = new Line[N]; // p左闭右开 q左闭右闭
q[F=R=0] = L[0];
for(int i = 1; i < N; i++) {
while(F < R && !OnLeft(L[i], p[R-1])) R--;
while(F < R && !OnLeft(L[i], p[F])) F++;
q[++R] = L[i];
if(fabs(Cross(q[R].v, q[R-1].v)) < EPS) {
R--;
if(OnLeft(q[R], L[i].P)) q[R] = L[i];
}
if(F < R) p[R-1] = GetIntersection(q[R-1], q[R]);
}
while(F < R && !OnLeft(q[F], p[R-1])) R--;
if(R - F < 2) return 0;
p[R] = GetIntersection(q[F], q[R]);
int CNT = 0;
for(int i = F; i <= R; i++) Ans[CNT++] = p[i];
return CNT;
}
int ConvexHull(Point *p, int N, Point *ch)
{
sort(p, p+N);
int R = 0;
for(int i = 0; i < N; i++) {
while(R > 1 && Cross(ch[R-1]-ch[R-2], p[i]-ch[R-2]) <= EPS) R--;
ch[R++] = p[i];
}
int F = R;
for(int i = N-2; i >= 0; i--) {
while(R > F && Cross(ch[R-1]-ch[R-2], p[i]-ch[R-2]) <= EPS) R--;
ch[R++] = p[i];
}
if(N > 1) R--;
return R;
}
Point A[MAXN+10], Ans[MAXN+10];
int main()
{
int n, r;
SF("%d%d", &n, &r);
for(int i = 0; i < n; i++) SF("%lf%lf", &A[i].x, &A[i].y);
int cnt = ConvexHull(A, n, Ans);
double dis = 0;
for(int i = 0; i < cnt; i++)
dis += GetDis(Ans[i], Ans[(i+1) % cnt]);
dis += PI * r * 2;
PF("%.0f", dis);
}