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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <bits/stdc++.h>


using namespace std;

typedef long long I;
typedef long double K;

typedef pair <I,I> point;
typedef pair <K,K> dPoint;

#define x first
#define y second

point operator+(point a, point b) { return {a.x + b.x, a.y + b.y}; }
point operator-(point a, point b) { return {a.x - b.x, a.y - b.y}; }
point operator*(point a, I f) { return {a.x * f, a.y * f}; }
point cross(point a) { return {-a.y, a.x}; }
I operator*(point a, point b) { return a.x * b.x + a.y * b.y; }

struct line {
    // (10^3, 10^3), 10^6
    point n; I c;
};


I det(const point &a, const point &b) {
    return a.x * b.y - a.y * b.x;
}

I norm(const point &a) {
    return a.x * a.x + a.y * a.y;
}

line span(point a, point b) {
    return {cross(b - a), det(b, a)};
}

bool inside(line l, point x) { return l.n * x <= l.c; }

dPoint intersection(line p, line q) {
    I d = det(p.n, q.n);
    assert(d != 0);

    auto cr = cross(p.n * q.c - q.n * p.c);
    return {(K) cr.x / d, (K) cr.y / d};
}

struct HalfplaneIntersection {
    struct ccw {
        I lower(point a) { return min(a.x, a.y) < 0 && a.y <= 0; }
        bool operator()(line l, line m) {
            return make_pair(lower(l.n), 0LL) < make_pair(lower(m.n), det(l.n, m.n));
        }
    };

    multiset <line, ccw> H;
    using HI = decltype(H)::iterator;

    HI cyc_next(HI it) { return (++it == H.end()) ? H.begin() : it; }
    HI cyc_prev(HI it) { return --(it == H.begin() ? H.end() : it); }

    bool redundant(HI it) {
        HI it1 = cyc_prev(it), it2 = cyc_next(it);
        if (it1 == it) return false;

        I d = det(it1->n, it2->n);
        I d1 = det(it->n, it2->n);
        I d2 = det(it1->n, it->n);

        if (d == 0) {
            if (d1 != 0) return false;

            for (HI jt : {it1, it2}) if (jt->n * it->n > 0) {
                return it->c * it->c * norm(jt->n) >= jt->c * jt->c * norm(it->n);
            }

            return false;
        }

        if (d1 * d < 0 || d2 * d < 0) {
            return false;
        }

        return (d < 0) xor (d * it->c >= d1 * it1->c + d2 * it2->c);
    }

    void add(line l) {
        HI it = H.insert(l);

        if (redundant(it)) { H.erase(it); return; }
        while (redundant(cyc_prev(it))) H.erase(cyc_prev(it));
        while (redundant(cyc_next(it))) H.erase(cyc_next(it));
    }
};

K solve(HalfplaneIntersection &planes) {
    vector <dPoint> poly;
    for (auto it = planes.H.begin(); it != planes.H.end(); it++) {
        auto l = *it;
        auto lNxt = *planes.cyc_next(it);

        if (det(l.n, lNxt.n) == 0) {
            return 0.0;
        } else {
            poly.push_back(intersection(l, lNxt));
        }
    }

    dPoint center = {0.0, 0.0};
    for (auto &p : poly) {
        center.x += p.x;
        center.y += p.y;
    }

    center.x /= poly.size();
    center.y /= poly.size();

    const K EPS = 1e-9;
    for (auto &e : planes.H) {
        if (e.n.x * center.x + e.n.y * center.y > e.c + EPS) {
            return 0.0;
        }
    }

    K ans = 0.0;
    for (int i = 0; i < (int) poly.size(); i++) {
        int j = (i + 1) % poly.size();
        ans += poly[i].x * poly[j].y - poly[i].y * poly[j].x;
    }

    ans /= 2.0;
    ans = abs(ans);

    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cout << setprecision(12) << fixed;

    int n;
    cin >> n;

    vector <vector<point>> towers(n);
    vector <point> allTowers;

    for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) {
        point p;
        cin >> p.x >> p.y;

        towers[i].push_back(p);
        allTowers.push_back(p);
    }

    HalfplaneIntersection planes;
    for (auto &pi : allTowers) for (auto &pj : allTowers) if (pi != pj) {
        line l = span(pi, pj);

        bool ok = true;
        for (int k = 0; k < n; k++) {
            int cnt = 0;
            for (auto &e : towers[k]) {
                cnt += inside(l, e);
            }

            if (cnt == 0) {
                ok = false;
                break;
            }
        }

        if (ok) {
            planes.add(l);
        }
    }

    cout << solve(planes);

    return 0;
}