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
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#define REP(i,x,v)for(int i=x;i<=v;i++)
#define REPD(i,x,v)for(int i=x;i>=v;i--)
#define FOR(i,v)for(int i=0;i<v;i++)
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define pb push_back
#define sz size()
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define IN(x,y) ((y).find((x))!=(y).end())
#define LOLDBG
#ifdef LOLDBG
#define DBG(vari) cout<<#vari<<" = "<<vari<<endl;
#define DBG2(v1,v2) cout<<(v1)<<" - "<<(v2)<<endl;
#else
#define DBG(vari)
#define DBG2(v1,v2)
#endif
#define CZ(x) scanf("%d",&(x));
#define CZ2(x,y) scanf("%d%d",&(x),&(y));
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
template<typename T,typename TT> ostream &operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream &operator<<(ostream &s,vector<T> t){s<<"{";FOR(i,t.size())s<<t[i]<<(i==t.size()-1?"":",");return s<<"}"<<endl; }

// Kod algorytmu przeciecia wielokąta z polplaszczyzna pochodzi z biblioteczki M. Cygana
const long double EPS = 1e-11;
inline bool IsZero(long double x){ return x>=-EPS && x<=EPS; }
#define POINTT long double
#define POINTR long double
POINTT maxv = 1000.0;
struct POINT {
    POINTT x,y;
    POINT(POINTT wx, POINTT wy) : x(wx), y(wy) {}
    POINT() {}
    bool operator ==(POINT& a) {return a.x==x && a.y==y;}
};
#define Det(p1,p2,w) ((p2.x-p1.x)*(w.y-p1.y)-(p2.y-p1.y)*(w.x-p1.x))
int sgn(long double x){ return IsZero(x)?0:(x < 0 ? -1 : 1); }
int LineCrossPoint(POINT p1, POINT p2, POINT l1, POINT l2, POINT &prz){
  long double t = (p1.x - p2.x) * (l1.y - l2.y) - (p1.y - p2.y) * (l1.x - l2.x);
  long double s = (l2.x - p2.x) * (l1.y - l2.y) - (l2.y - p2.y) * (l1.x - l2.x);
  if (IsZero(t)) return IsZero(s)?2:0;
  prz.x = (s/t) * p1.x + (1-s/t) * p2.x;
  prz.y = (s/t) * p1.y + (1-s/t) * p2.y;
  return 1;
}

void PolygonSemiplaneCross(vector<POINT> &v, POINT &a, POINT &b, vector<POINT> &r){
  int n = v.size(); r.clear();
  int ost = sgn(Det(a,b,v[n-1])), f = 1;
  FOR(i,n){
    int akt = sgn(Det(a,b,v[i]));
    if (akt * ost == -1){
      POINT x;
      LineCrossPoint(a,b,v[(i+n-1)%n],v[i],x);
      r.pb(x);
    }
    if (akt >= 0) r.pb(v[i]);
    if (akt > 0) f = 0;
    ost = akt;
  }
  if (f) r.clear();
}

long double PolygonArea(vector<POINT> p) {
    POINTR area=0; int s = p.size();
    FOR(x,s) area += (p[x].x)*(p[(x+1)%s].y) - (p[x].y)*(p[(x+1)%s].x);
    return (long double)(max(area,-area))/2;
}

POINT a[101][2];


int main()
{
    int n;
    cin>>n;
    FOR(i,n)
    {
        POINTT a1,b1,a2,b2;
        cin>>a1>>b1>>a2>>b2;
        a[i][0]=POINT(a1,b1);
        a[i][1]=POINT(a2,b2);
    }
    vector<pair<POINT,POINT> > hps;
    POINT x,y;
    FOR(i,n)FOR(j,n)
    {
        if (i==j) continue;
        FOR(s1,2)FOR(s2,2)
        {
            x = a[i][s1];
            y = a[j][s2];
            bool ok=1;
            FOR(k,n)
            {
                if (k==i || k==j) continue;
                if (!(Det(x,y,a[k][0])> - EPS || Det(x,y,a[k][1]) > -EPS)) {ok=0;break;}

            }
            if (ok) hps.pb(mp(x,y));

        }
    }

    vector<POINT> v;

    v.pb(POINT(-maxv,-maxv));
    v.pb(POINT(-maxv,maxv));
    v.pb(POINT(maxv,maxv));
    v.pb(POINT(maxv,-maxv));

    FOR(i,hps.sz)
    {
        vector<POINT> r;
        PolygonSemiplaneCross(v, hps[i].fi, hps[i].se, r);
        v = r;
        if (v.sz<=2) break;
    }
    cout<<setprecision(13)<<fixed;
    if (v.sz<=2) cout<<0.0<<"\n";
    else cout<<PolygonArea(v)<<"\n";



  return 0;
}