61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
#include <stdio.h>
|
|
#include <iostream>
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
using namespace std;
|
|
const int N = 1e3 + 5;
|
|
const double PI = acos(-1.0), eps = 1e-8;
|
|
struct Point {
|
|
double x, y;
|
|
Point () {}
|
|
Point (double xx, double yy) : x(xx), y(yy) {}
|
|
Point friend operator - (Point a, Point b) {
|
|
return Point(a.x - b.x, a.y - b.y);
|
|
}
|
|
double friend operator ^ (Point a, Point b) {
|
|
return a.x * b.y - b.x * a.y;
|
|
}
|
|
bool friend operator < (Point a, Point b) {
|
|
if (a.y == b.y) return a.x < b.x;
|
|
return a.y < b.y;
|
|
}
|
|
} p[N];
|
|
int n, L, q[N];
|
|
double dist (Point a, Point b){
|
|
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
|
|
}
|
|
int Sign(double x) {
|
|
if (x >= -eps && x <= eps) return 0;
|
|
return x > eps ? 1 : -1;
|
|
}
|
|
bool cmp(Point a, Point b) {
|
|
int s = Sign((a - p[1]) ^ (b - p[1]));
|
|
if(s > 0 || (s == 0 && dist(a, p[1]) < dist(b, p[1]))) return 1;
|
|
else return 0;
|
|
}
|
|
double Graham() {
|
|
sort(p + 1, p + n + 1);
|
|
sort(p + 1, p + n + 1, cmp);
|
|
int top = 3;
|
|
q[1] = 1, q[2] = 2, q[3] = 3;
|
|
for (int i = 4; i <= n; i++) {
|
|
while(top > 1 && Sign((p[q[top]] - p[q[top - 1]]) ^ (p[i] - p[q[top]])) <= 0)
|
|
top--;
|
|
q[++top] = i;
|
|
}
|
|
double res = 0;
|
|
for (int i = 1; i < top; i++)
|
|
res += dist(p[q[i]], p[q[i + 1]]);
|
|
res += dist(p[q[1]], p[q[top]]);
|
|
res += 2.0 * PI * L;
|
|
return res;
|
|
}
|
|
int main() {
|
|
// freopen("1.txt", "r", stdin);
|
|
scanf("%d %d", &n, &L);
|
|
for (int i = 1; i <= n; i++)
|
|
scanf("%lf %lf", &p[i].x, &p[i].y);
|
|
printf("%d\n", (int)(Graham() + 0.5));
|
|
return 0;
|
|
}
|