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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include<bits/stdc++.h>

using namespace std;

int ax[109];
int ay[109];
int bx[109];
int by[109];

struct poi{
    int x;
    int y;
    int num;
    int wx;
    int wy;
};

vector<poi> sorted[209];

vector<poi> inp;
vector<poi> test;


int AA, BB;

bool opera(poi a, poi b){
    if(a.x*AA + a.y*BB < b.x*AA + b.y*BB)return true;
    else return false;
}

vector<poi> proste;
int odw[1000000];
vector<long double> konx;
vector<long double> kony;

long double det(long double x0, long double y0, long double x1, long double y1, long double x2, long double y2){
    return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);
}

long double odl(long double x0, long double y0, long double x1, long double y1){
    return (x0-x1)*(x0-x1)+(y0-y1)*(y0-y1);
}

pair<long double, long double> gdzieprzec(long double x0, long double y0, long double x1, long double y1, long double x2, long double y2, long double x3, long double y3){
    long double A = y1-y0;
    long double B = -(x1-x0);
    long double C = -A*x0-B*y0;
    long double A2 = y3-y2;
    long double B2 = -(x3-x2);
    long double C2 = -A2*x2-B2*y2;
    long double W = A*B2-A2*B;
    long double Wx = (-C)*B2 - (-C2)*B;
    long double Wy =  A*(-C2) - A2*(-C);

    if(W == 0)return make_pair(110000009, 110000009);
    else{
        return make_pair(Wx/W, Wy/W);
    }


}

long double weakprec= -0.0000000000001;

bool nieacc(long double x, long double y){
    for(int i=0;i<proste.size();++i){
        if(det(proste[i].x, proste[i].y, proste[i].wx, proste[i].wy, x, y)<weakprec){
            //cerr<<proste[i].x<<" "<<proste[i].y<<" "<<proste[i].wx<<" "<<proste[i].wy<<" ";
            //cerr<<i<<" "<<det(proste[i].x, proste[i].y, proste[i].wx, proste[i].wy, x, y)<<"  ";
            return 1;
        }
    }
    return 0;
}

int dfs(int pos){//cerr<<pos<<"!!"<<endl;
    pair<long double, long double> przec;
    przec.first =100000009;
    przec.second=100000009;
    int gdzie=-1;
    for(int i=0;i<proste.size();++i){
        if(i==pos)continue;
        if(det(proste[pos].x, proste[pos].y, proste[pos].wx, proste[pos].wy, proste[i].wx, proste[i].wy)>0
        && det(proste[pos].x, proste[pos].y, proste[pos].wx, proste[pos].wy, proste[i].x, proste[i].y)<=0){
            pair<long double, long double> temp= gdzieprzec(proste[pos].x, proste[pos].y, proste[pos].wx, proste[pos].wy, proste[i].x, proste[i].y, proste[i].wx, proste[i].wy);
            if(odl(przec.first, przec.second, proste[pos].x, proste[pos].y)>odl(temp.first, temp.second, proste[pos].x, proste[pos].y)){
                przec=temp;
                gdzie=i;
            }
        }
    }
    if(gdzie==-1)return -1;
    //cerr<<przec.first<<" ! "<<przec.second<<" "<<gdzie<<endl;
    if(odw[pos]==1){
        konx.push_back(przec.first);
        kony.push_back(przec.second);
        return pos;
    }//cerr<<gdzie<<"_"<<endl;
    odw[pos]=1;
    int ret=dfs(gdzie);
    odw[pos]=0;
    if(ret==-1)return -1;
    if(odw[ret]==1){
        konx.push_back(przec.first);
        kony.push_back(przec.second);
    }
    return ret;
}

int iltab[109];

poi znajdzc(){//cerr<<"!lol! "<<AA<<" "<<BB<<endl;
    for(int i=0;i<109;++i)iltab[i]=0;
    int lc=AA*test[0].x+BB*test[0].y;
    int konczy=0;
    poi last;
    int kx=0;
    int ky=0;
    for(int i=0;i<test.size();++i){//cerr<<test[i].x<<" "<<test[i].y<<"for\n";
        if(konczy && AA*test[i].x+BB*test[i].y>lc){
            last.num=-17;
            return last;
        }
        if(iltab[test[i].num]==1){
            if(konczy == 1){
                int k2x=test[i].x;
                int k2y=test[i].y;
                int xxx=0;
                int yyy=0;
                if(AA >0)xxx-=1000000;
                else xxx+=1000000;
                if(BB >0)yyy-=1000000;
                else yyy+=1000000;
                if(det(kx, ky, k2x, k2y, xxx, yyy)>0){
                    swap(kx, k2x);
                    swap(ky, k2y);
                }

                //cerr<<kx<<" "<<ky<<"  "<<k2x<<" "<<k2y<<endl;
                last.num=19;
                last.x=kx;
                last.y=ky;
                last.wx=k2x;
                last.wy=k2y;
                return last;
            }
            konczy=1;
            last=test[i];
            kx=test[i].x;
            ky=test[i].y;
        }
        iltab[test[i].num]=1;
        lc=AA*test[i].x+BB*test[i].y;
    }

}

int skrot[3000][3000];

int main(){
    ios_base::sync_with_stdio(0);
    cout<<setprecision(16);
    cout<<fixed;
    int n;cin>>n;
    for(int i=0;i<n;++i){
        cin>>ax[i]>>ay[i]>>bx[i]>>by[i];
    }

    int lowpos=-1;
    int lowy=1000000000;
    for(int i=0;i<n;++i){
        poi boi;
        boi.x=ax[i];
        boi.y=ay[i];
        boi.num=i;
        boi.wx=-123123;
        boi.wy=-123123;
        inp.push_back(boi);
    }
    for(int i=0;i<n;++i){
        poi boi;
        boi.x=bx[i];
        boi.y=by[i];
        boi.num=i;
        boi.wx=-123123;
        boi.wy=-123123;
        inp.push_back(boi);
    }

    for(int i=0;i<2*n;++i){
        for(int j=0;j<2*n;++j){
            if(i==j)continue;
            test=inp;
            AA = inp[i].y-inp[j].y;
            BB = -(inp[i].x-inp[j].x);
            int d=__gcd(AA, BB);if(d<0)d=-d;
            AA/=d;
            BB/=d;
            //cerr<<AA<<" "<<BB<<" "<<__gcd(AA, BB)<<endl;
            //cerr<<AA<<" "<<BB<<endl;
            if(skrot[1500+AA][1500+BB]==1)continue;
            skrot[1500+AA][1500+BB]=1;

            sort(test.begin(), test.end(), opera);
            poi boi = znajdzc();
            if(boi.num!=-17){
                proste.push_back(boi);
            }

        }
    }



    //cerr<<gdzieprzec(0, 0, 100, 100, 1, 0, 0, 1).first<<endl;
    //cerr<<gdzieprzec(0, 0, 100, 100, 1, 0, 0, 1).second<<endl;
    //cerr<<"\n"<<proste.size()<<endl;
    dfs(0);//cerr<<"??"<<endl;
    long double wyn=0;
    //for(int i=0;i<konx.size();++i)cerr<<konx[i]<<" "<<kony[i]<<endl;
    for(int i=0;i<konx.size();++i)if(nieacc(konx[i], kony[i])){
        //cerr<<"!!!!!"<<konx[i]<<" "<<kony[i]<<" "<<i<<endl;
        cout<<wyn<<endl;
        return 0;
    }
    for(int i=1;i<(int)konx.size()-1;++i){
        wyn+=-det(konx[0], kony[0], konx[i], kony[i], konx[i+1], kony[i+1])/2;

    }

    cout<<wyn<<endl;



    return 0;
}

/*
4
0 0 4 1
4 0 2 2
2 2 -2 2
-1 5 0 0

3
0 0 0 1
0 100 0 101
100 50 100 51

*/