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
| #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std;
long long sqr(long long x) __attribute__((always_inline));
long long sqr(long long x) { return x * x; }
struct Point { Point(int x = 0, int y = 0) : x(x), y(y) {} inline Point &operator-=(const Point &o) { x -= o.x; y -= o.y; return *this; } double dis() const __attribute__((always_inline)); int x, y; };
double Point::dis() const { return sqrt(sqr(x) + sqr(y)); }
inline Point operator-(Point a, const Point &b) { return a -= b; }
long long det(const Point &a, const Point &b) __attribute__((always_inline)); long long dot(const Point &a, const Point &b) __attribute__((always_inline)); long long get_sum(int i, int j) __attribute__((always_inline)); int nxt(int i) __attribute__((always_inline)); double solve() __attribute__((always_inline));
long long det(const Point &a, const Point &b) { return (long long)a.x * b.y - (long long)a.y * b.x; }
long long dot(const Point &a, const Point &b) { return (long long)a.x * b.x + (long long)a.y * b.y; }
const int N = 40000;
int n; Point p[N]; long long sum[N + 1];
long long get_sum(int i, int j) { long long s = sum[j] - sum[i]; return i <= j ? s : sum[n] + s; }
int nxt(int i) { return (i + 1) % n; }
double solve() { sum[0] = 0; for (int i = 0; i < n; ++i) sum[i + 1] = sum[i] + det(p[i], p[(i + 1) % n]); double result = INFINITY; for (int i = 0, j = 0; i < n; ++i) { while (dot(p[nxt(i)] - p[i], p[nxt(j)] - p[j]) > 0) j = nxt(j); Point a = p[nxt(i)] - p[i]; Point b = p[j] - p[i]; double n = a.dis(); result = min(result, det(a, b) / n * dot(a, b) / n - (get_sum(i, j) + det(p[j], p[i]))); if (i == j) return 0.; } return .5 * result; }
int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d%d", &p[i].x, &p[i].y); solve(); if (sum[n] < 0) reverse(p, p + n); double result = solve(); for (int i = 0; i < n; ++i) p[i].x *= -1; reverse(p, p + n); result = min(result, solve()); printf("%.10f\n", result); return 0; }
|