meaning of the title
The coordinates of n points on the plane are given. You need to build a fence to enclose all points, and the distance between the fence and all points is not less than l. Find the minimum length of the fence.
\(n \leqslant 10^5\)
Sol
First of all, if there is no limit of l, it is obviously the length of convex hull.
Now that the distance is limited, it is obvious that the fence originally built on the convex hull needs to move outwards by \ (l \), and at the same time, it will increase some places not surrounded
Because the diplomatic sum of polygons is 360, and according to the nature of complement angle, drawing a picture shows that this piece is a circle with a radius of \ (l \).
Because the total answer is convex circumference + \ (2 \pi l \)
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int MAXN = 1e5 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int N, top; struct Point { double x, y; Point operator - (const Point &rhs) const { return {x - rhs.x, y - rhs.y}; } Point operator + (const Point &rhs) const { return {x + rhs.x, y + rhs.y}; } double operator ^ (const Point &rhs) const { return x * rhs.y - y * rhs.x; } bool operator < (const Point &rhs) const { return x == rhs.x ? y < rhs.y : x < rhs.x; } }p[MAXN], q[MAXN]; template<typename A> A sqr(A x) { return x * x; } double dis(Point a, Point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); } void insert(Point now) { while(top > 1 && ((q[top] - q[top - 1]) ^ (now - q[top - 1])) < 0) top--; q[++top] = now; } int main() { N = read(); double L = read(); for(int i = 1; i <= N; i++) p[i].x = read(), p[i].y = read(); sort(p + 1, p + N + 1); q[top = 1] = p[1]; for(int i = 2; i <= N; i++) insert(p[i]); for(int i = N - 1; i >= 1; i--) insert(p[i]); double ans = 0; for(int i = 1; i < top; i++) ans += dis(q[i], q[i + 1]); ans += 2 * acos(-1) * L + 0.5; printf("%d\n", (int) ans); }