1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<long long, long long> pll; #define fi first #define se second #define ls p<<1 #define rs p<<1|1 const int N = 3e6+10; const int INF=2e9; const double eps = 1e-9, pi = acos(-1.0);
int n, m;
int sgn(double x){ if(fabs(x) < eps) return 0; if(x > 0) return 1; return -1; }
struct point{ double x, y; point(double a = 0.0, double b = 0.0) : x(a), y(b){} bool operator < (point t) const{ if(sgn(x - t.x) == 0) return y < t.y; return x < t.x; } point operator - (point p) const{ return {x - p.x, y - p.y}; } double operator ^ (point p) const{ return x * p.y - y * p.x; } }p[N], ans[N];
double dis(point a, point b){ a = a - b; return sqrt(a.x * a.x + a.y * a.y); }
double Andrew(){ sort(p, p + n); int p1 = 0, p2; for(int i = 0; i < n; i++){ while(p1 > 1 && sgn((ans[p1] - ans[p1 - 1]) ^ (p[i] - ans[p1 - 1])) <= 0) p1--; ans[++p1] = p[i]; } p2 = p1; for(int i = n - 2; i >= 0; i--){ while(p2 > p1 && sgn((ans[p2] - ans[p2 - 1]) ^ (p[i] - ans[p2 - 1])) <= 0) p2--; ans[++p2] = p[i]; } double sum = 0; for(int i = 1; i < p2; i++){
sum += dis(ans[i], ans[i + 1]); }
return sum; }
void solve(){ int pn; double r; cin >> pn >> r; for(int i = 0, c; i < pn; i++){ cin >> c; for(int j = 0; j < c; j++){ double x, y; cin >> x >> y; p[n++] = point(x, y); } } double res = Andrew() + 2. * pi * r; printf("%.5lf", res); }
int main() { int T=1; ios::sync_with_stdio(false); for(int i=1;i<=T;i++) {
solve(); } }
|