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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* korzystam z biblioteczki teamu
Wojciech Nadara
Marcin Smulewicz
Marek Sokołowski*/
#include<bits/stdc++.h>

using namespace std;

//#define int long long
#define double long double
#define mod 1000000007ll
#define INF 1000000000000000000ll

#define x first
#define y second
#define ilo( a, b, c ) ( (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y) )

const double eps = 1e-9;
struct Point {
	double x, y;
	Point() {}
	Point(double a, double b) : x(a), y(b) {}
	Point operator+(const Point& a) const {
		Point p(x + a.x, y + a.y);
		return p;
	}
	Point operator-(const Point& a) const {
		Point p(x - a.x, y - a.y);
		return p;
	}
	Point operator*(double a) const {
		Point p(x * a, y * a);
		return p;
	}
	Point& operator-=(const Point& a) {
		x -= a.x;
		y -= a.y;
		return *this;
	}
	double CrossProd(const Point& a) const {
		return x * a.y - y * a.x;
	}
	double CrossProd(Point a, Point b) const {
		a -= *this;
		b -= *this;
		return a.CrossProd(b);
	}
};

struct Line {
	Point p[2];
	Line(Point a, Point b) {
		p[0] = a;
		p[1] = b;
	}
	Point& operator[](int a) {
		return p[a];
	}
};

bool PtBelongToLine(Line l, Point p) {
	return abs(l[0].CrossProd(l[1], p)) < eps;
}

vector<Point> InterLineLine(Line a, Line b) {
    Point vec_a = a[1] - a[0];
    Point vec_b1 = b[1] - a[0];
    Point vec_b0 = b[0] - a[0];
    double tr_area = vec_b1.CrossProd(vec_b0);
    double quad_area = vec_b1.CrossProd(vec_a) + vec_a.CrossProd(vec_b0);
    if (abs(quad_area) < eps) {
        if (PtBelongToLine(b, a[0])) { return {a[0], a[1]}; }
        else { return {}; }
    }
    return {a[0] + vec_a * (tr_area / quad_area)};
}

struct punkt {
    int x, y, id;
};

struct wektor {
    int x1, y1, x2, y2;
    int xx, yy;
    bool polowa;

    wektor( int a, int b, int c, int d ) {
        x1 = a; y1 = b; x2 = c; y2 = d;
        xx = x2-x1;
        yy = y2-y1;
        if( xx>=0 ) polowa = 0;
        else polowa = 1;
        if( xx==0 && yy<0 ) polowa = 1;
    }

    bool operator < ( const wektor & other ) const {
        if( polowa == other.polowa ) {
			int i = ilo( make_pair( 0, 0 ), make_pair( xx, yy ), make_pair( other.xx, other.yy ) );
            if( i == 0 ) {
				if( ilo( make_pair( x1, y1 ), make_pair( x2, y2 ), make_pair( other.x1, other.y1 ) ) == 0 ) return 0;
				return make_pair( x1, y1 ) < make_pair( other.x1, other.y1 );
			}
            return i < 0;
        }
        return polowa < other.polowa;
    }

    void wypisz() {
        cout << xx << " " << yy << "  ";
        cout << x1 << " " << y1 << "  " << x2 << " " << y2 << "  " << polowa << endl;
    }

    Line foo() const {
        return Line( {(double)x1, (double)y1}, {(double)x2, (double)y2} );
    }
};

int n;
vector<punkt> v;
vector<pair<punkt, punkt> > pun;
set<wektor> tab;
int ile[10000];

vector<pair<double, double> > wyn;

void spr( punkt a, punkt b ) {
    if( a.x==b.x && a.y==b.y ) return;
    int p, q;
    int czy=0;
    for( pair<punkt, punkt> & i : pun ) {
        p = ilo( a, b, i.first );
        q = ilo( a, b, i.second );
        if( p>0 && q>0 ) return;
        if( p>=0 && q>=0 ) czy++;
    }
    if( czy > 1 ) {
        tab.insert( {a.x, a.y, b.x, b.y} );
    }
}

double res;
pair<double, double> zero {0, 0};

void otocz() {
	vector<pair<double, double> > oto;
	for( pair<double, double> i : wyn ) {
		int sz = oto.size();
		while( sz>1 && ilo( oto[sz-1], i, oto[sz-2] )>= 0 ) {
			oto.pop_back();
			sz--;
		}
		oto.push_back( i );
	}
	for( int i=1; i<(int)oto.size(); i++ ) {
		//cout << oto[i].x << " " << oto[i].y << endl;
		res += ilo( zero, oto[i-1], oto[i] );
	}
}

int32_t main() {
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );

    cin >> n;
    for( int a, b, c, d, i=1; i<=n; i++ ) {
        cin >> a >> b >> c >> d;
        v.push_back( {a, b, i} );
        v.push_back( {c, d, i} );
        pun.push_back( {{a, b, i}, {c, d, i}} );
    }

    for( punkt i : v ) {
        for( punkt j : v ) {
            spr( i, j );
        }
    }


    /*for( auto i : tab ) {
        i.wypisz();
    }*/

	bool czy=true;
	for( auto i = tab.begin(); i!=tab.end(); i++ ) {
		for( auto j=i; j!=tab.end(); j++ ) {
			vector<Point> v = InterLineLine( i->foo(), j->foo() );
			if( v.empty() ) continue;
			czy = true;
			for( auto & k : tab ) {
				//cout << ilo( make_pair( k.x1, k.y1 ), make_pair( k.x2, k.y2 ), v.front() ) << endl;
				if( ilo( make_pair( k.x1, k.y1 ), make_pair( k.x2, k.y2 ), v.front() ) > eps ) {
					czy = false;
					break;
				}
			} 
			if( czy ) wyn.push_back( {v.front().x, v.front().y} );
		}
	}
    czy=1;
	while( czy ) {
		czy = 0;
		for( int i=1; i<(int)wyn.size(); i++ ) {
			if( abs( wyn[i].x-wyn[i-1].x ) < eps && abs( wyn[i].y-wyn[i-1].y ) < eps ) {
				wyn.erase( wyn.begin()+i );
				czy = 1;
			}
		}
		sort( wyn.begin(), wyn.end() );
	}
	sort( wyn.begin(), wyn.end() );
	/*cout << endl;
    for( pair<double, double> i : wyn ) {
        cout << fixed << setprecision( 10 ) << i.x << " " << i.y << endl;
    }*/
    
    //cout << endl;   
    otocz();
    reverse( wyn.begin(), wyn.end() );
    //cout << endl;
    otocz();
    cout << fixed << setprecision( 16 ) << abs( res/2 );


    return 0;
}/*

*/