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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
| #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll M = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1.0); int sign(double x) { if (fabs(x) < eps) return 0; if (x < 0) return -1; return 1; }; struct Point { ll x, y; Point(double a = 0, double b = 0) { x = a, y = b; } Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); } Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); } Point operator*(const double &a) const { return Point(x * a, y * a); } Point operator/(const double &a) const { return Point(x / a, y / a); } bool operator==(const Point &a) const { return !sign(x - a.x) && !sign(y - a.y); } bool operator<(const Point &a) const { return (fabs(x - a.x) < eps) ? (y < a.y) : (x < a.x); } }; struct Line { Point a, v; Line(Point x = Point(), Point y = Point()) { a = x, v = y; } }; const int dots_num = 100005; struct Poly { int num; Point dots[dots_num]; Poly(int x = 0) { num = x; } }; ll dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } ll cross(Point a, Point b) { return a.x * b.y - b.x * a.y; } ll get_length2(Point a) { return abs(dot(a, a)); } ll polygon_square2(Poly m) { ll ans = 0; for (int i = 0; i < m.num; i++) { ans += cross(m.dots[i], m.dots[(i + 1) % m.num]); } return abs(ans); } int pos;
int d[4 * dots_num]; int manacher(Poly v) { vector<pair<ll, pair<Point, Point>>> str; int axiss = 0; for (int i = 0; i < v.num; i++) { str.push_back( make_pair(get_length2(v.dots[(i - 1 + v.num) % v.num] - v.dots[(i + 1) % v.num]), make_pair(v.dots[(i - 1 + v.num) % v.num], v.dots[(i + 1) % v.num]))); str.push_back(make_pair(get_length2(v.dots[i] - v.dots[(i + 1) % v.num]), make_pair(v.dots[i], v.dots[(i + 1) % v.num]))); } for (int i = 0; i < v.num << 1; i++) { str.push_back(str[i]); } int mx = 0, id; for (int i = 0; i < str.size(); i++) { if (i < mx) d[i] = min(mx - i + 1, d[2 * id - i]); else d[i] = 1; while (i + d[i] <= str.size() && i - d[i] >= 0 && !sign(str[i + d[i]].first - str[i - d[i]].first)) d[i]++; if (d[i] + i - 1 > mx) { mx = d[i] + i - 1; id = i; } if (i >= v.num && i < 2 * v.num && 1 + 2 * (d[i] - 1) >= 2 * v.num) axiss++, pos = i -v.num; } return axiss; }
double distance_to_line(Point p, Line m) { return fabs(cross(p - m.a, m.v) / sqrt(get_length2(m.v))); } double polygon_center(Poly m, Line ml) { Point ans(0, 0); pair<double, double> mp; if (sign(polygon_square2(m)) == 0) return 0; for (int i = 0; i < m.num; i++) { ans = ans + (m.dots[i] + m.dots[(i + 1) % m.num]) * cross(m.dots[i], m.dots[(i + 1) % m.num]); } mp.first = ans.x / 3.0 / (polygon_square2(m)); mp.second = ans.y / 3.0 / (polygon_square2(m)); pair<double, double> tmp = {mp.first - ml.a.x, mp.second - ml.a.y}; double dis = fabs((tmp.first * ml.v.y - ml.v.x * tmp.second) / sqrt(get_length2(ml.v))); return dis; }
int main() { int n; cin >> n; Poly a = Poly(n), h = Poly(0); for (int i = 0; i < n; i++) { scanf("%lld%lld", &a.dots[i].x, &a.dots[i].y); } int as = manacher(a); if (as == 0) { printf("0"); } else if (as == 1) { vector<Point> u; for (int i = 0; i < a.num; i++) { u.push_back(a.dots[i] + a.dots[i]); u.push_back(a.dots[i] + a.dots[(i + 1) % a.num]); } Point lp = u[(pos + a.num) % (2 * a.num)], lv = lp - u[pos]; int l = (pos - 1 + (2 * a.num)) % (2 * a.num), r = (pos + 1) % (2 * a.num); long double ans = 0, k2 = 0; for (; l != r; l = (l - 1 + (2 * a.num)) % (2 * a.num), r = (r + 1) % (2 * a.num)) { long double k1 = sqrt(get_length2(u[l] - u[r])) / 2; long double h = fabs(dot(u[r] - u[(r - 1 + (2 * a.num)) % (2 * a.num)], lv)); ans += h * (k1 * k1 + k2 * k2 + k1 * k2); k2 = k1; } printf("%.12Lf", PI * ans / 24 / sqrt(get_length2(lv))); } else { Point m = Point(); for (int i = 0; i < n; i++) { m = m + a.dots[i]; } __int128 r = 0; for (int i = 0; i < n; i++) { r = max(r, (__int128)(m.x - n * a.dots[i].x) * (m.x - n * a.dots[i].x) + (__int128)(m.y - n * a.dots[i].y) * (m.y - n * a.dots[i].y)); } printf("%.12Lf", (long double)4.0 / 3 * PI * sqrtl(r) / n * r / n / n); } }
|