#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; const double PI = acos(-1); int n, T; double L; struct Point { double x, y; Point(double x = 0, double y = 0): x(x), y(y) {} }; typedef Point Vector; typedef vector<Point> Polygon; Vector operator +(Vector A, Vector B)// { return Vector(A.x + B.x, A.y + B.y); } Vector operator -(Point A, Point 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); } bool operator <(const Point &a, const Point &b)// { return a.x < b.x || (a.x == b.x && a.y < b.y); } const double eps = 1e-10; int dcmp(double x)// { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } bool operator ==(const Point &a, const Point &b)// { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; } Point read_point() { double X, Y; scanf("%lf%lf", &X, &Y); return Point(X, Y); } 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; } vector<Point> ConvexHull(vector<Point>& p) { sort(p.begin(), p.end()); p.erase(unique(p.begin(), p.end()), p.end()); int n = p.size(); int m = 0; vector<Point> ch(n + 1); 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--; ch.resize(m); return ch; } Polygon P; int main(int argc, char const *argv[]) { scanf("%d", &T); while (T--) { scanf("%d%lf", &n, &L); for (int i = 0; i < n; i++) P.push_back(read_point()); Polygon newp = ConvexHull(P); int lenn = newp.size(); newp.push_back(newp.front()); double ans = 0; for (int i = 0; i < lenn; i++) ans += Length(newp[i] - newp[i + 1]); ans += 2.0 * PI * L; printf("%.0lf\n", ans); if (T) printf("\n"); } return 0; }
所有角加起来为360度,其余纯模板