#include <bits/stdc++.h> using namespace std; #define pb push_back #define BP push_back #define mp make_pair #define MP make_pair #define pbp(a, b) pb(mp(a, b)) #define PBP(a, b) PB(MP(a, b)) #define fst first #define snd second #define int4 int32_t #define LL long long #define int LL #define FOR(i,a,b) for(int(i)=(a)-(int)((a)>(b));(i)!=(b)-(int)((a)>(b));(i)+=((a)<(b))?1:-1) #define REP(b) FOR(i, 0, b) #define REPI(i, b) FOR(i, 0, b) #define REP1(b) FOR(i, 1, (b)+1) #define REPI1(i, b) FOR(i, 1, (b)+1) #define REV(b) FOR(i, b, 0) #define REV1(b) FOR(i, (b)+1, 1) #define ITER(j, b) for(auto (j) : (b)) #define ALL(x) (x).begin(), (x).end() #define BOTH(x) (x).fst, (x).snd #define sz(x) ((int)(x).size()) #define SZ(x) ((int)(x).size()) #define SKP(...) (__VA_ARGS__) typedef vector<int> VI; typedef pair<int,int> PII; typedef long double LD; template<class C> void minu(C& a4, C b4) { a4 = min(a4, b4); } template<class C> void maxu(C& a4, C b4) { a4 = max(a4, b4); } template<class TH> void _dbg(const char *sdbg, TH h) { while(*sdbg==' ') sdbg++; if(*sdbg!='\"' && *sdbg!='\'' && (*sdbg!='S' || *(sdbg+1)!='K' || *(sdbg+2)!='P'))cerr<<" "<<sdbg<<"="<<h<<"\n"; else cerr<<" "<<h<<"\n"; } template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg==' ') sdbg++; if(*sdbg!='\"' && *sdbg!='\'' && (*sdbg!='S' || *(sdbg+1)!='K' || *(sdbg+2)!='P')) { cerr<<" "; while(*sdbg!=',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, a...); } else { while(*sdbg!=',') sdbg++; cerr<<" "<<h<<","; _dbg(sdbg+1, a...); } } template<class T> ostream &operator<<(ostream &os, vector<T> V) { os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]"; } template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.fst << "," << P.snd << ")"; } int XXXX_XXXX_XXXX; #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define deb(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define scanf(...) (XXXX_XXXX_XXXX=scanf(__VA_ARGS__)) #else #define debug(...) {} #define cerr if(0)cout #endif struct XX_ld { LD v; XX_ld(LD V) : v(V) {} }; typedef XX_ld ld; LD eps=1e-11; inline ld operator +(ld a, ld b) { return ld(a.v+b.v); } inline ld operator -(ld a, ld b) { return ld(a.v-b.v); } inline ld operator -(ld a) { return ld(-a.v); } inline ld operator *(ld a, ld b) { return ld(a.v*b.v); } inline ld operator /(ld a, ld b) { return ld(a.v/b.v); } inline bool operator ==(ld a, ld b) { return a.v+eps >= b.v && a.v-eps <= b.v; } inline bool operator <(ld a, ld b) { return a.v <= b.v && !(a == b); } inline bool operator >(ld a, ld b) { return a.v >= b.v && !(a == b); } inline bool operator <=(ld a, ld b) { return a.v <= b.v || (a == b); } inline bool operator >=(ld a, ld b) { return a.v >= b.v || (a == b); } typedef pair <ld, ld> PLL; int strona(PLL &a, PLL &b, PLL &c) { ld tmp=a.fst*b.snd+b.fst*c.snd+c.fst*a.snd-(a.fst*c.snd+b.fst*a.snd+c.fst*b.snd); if(tmp>0) return -1; if(tmp<0) return 1; return 0; } ostream &operator<<(ostream &os, ld &b) { return os << b.v; } bool gor_cmp(PLL a, PLL b) { return mp(-a.fst.v, -a.snd.v) < mp(-b.fst.v, -b.snd.v); } bool dol_cmp(PLL a, PLL b) { return mp(a.fst.v, a.snd.v) < mp(b.fst.v, b.snd.v); } ld przec(ld a1, ld b1, ld a2, ld b2) { return (b2-b1)/(a1-a2); } ld pole(ld a1, ld b1, ld a2, ld b2, ld poc, ld kon) //1 to gora, 2 to dol { //deb(a1, b1, a2, b2, poc, kon); if(poc>=kon) return 0; ld p1=a1*poc+b1; ld k1=a1*kon+b1; ld p2=a2*poc+b2; ld k2=a2*kon+b2; if(p1>=p2 && k1>=k2) { //deb("oba", p1, k1, p2, k2, SKP((kon-poc)*((p1-p2)+(k1-k2))/2)); return (kon-poc)*((p1-p2)+(k1-k2))/2; } if(p1>=p2) { kon=przec(a1, b1, a2, b2); //deb("pie", p1, k1, p2, k2, kon, SKP((kon-poc)*((p1-p2)+(k1-k2))/2)); return (kon-poc)*(p1-p2)/2; } if(k1>=k2) { poc=przec(a1, b1, a2, b2); //deb("dru", p1, k1, p2, k2, poc, SKP((kon-poc)*((p1-p2)+(k1-k2))/2)); return (kon-poc)*(k1-k2)/2; } //deb(p1, k1, p2, k2); return 0; } int32_t main() { int n; scanf("%lld", &n); vector <pair <PLL, PLL> > pary; vector <pair <PLL, int> > wieze; REP(n) { int a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d); auto p1=mp(a, b), p2=mp(c, d); pary.pb(mp(p1, p2)); wieze.pb(mp(p1, i)); wieze.pb(mp(p2, i)); } vector <pair <PLL, PLL> > ogr; REP(sz(wieze)) { REPI(j, sz(wieze)) { if(i!=j) { int str[n]; FOR(x, 0, n) str[x]=0; bool nicprawo=1; ITER(w, wieze) { //debug(i, j, wieze[i].fst, wieze[j].fst, w.fst, SKP(strona(wieze[i].fst, wieze[j].fst, w.fst))); str[w.snd]+=strona(wieze[i].fst, wieze[j].fst, w.fst); if(str[w.snd]==2) nicprawo=0; } if(nicprawo) { ogr.pbp(wieze[i].fst, wieze[j].fst); } } } } //debug(ogr); ld ogrlew=-1000000; ld ogrpra=1000000; vector <PLL> gor, dol; ITER(par, ogr) { auto p1=par.fst, p2=par.snd; //debug(par); if(p1.fst==p2.fst) { if(p1.snd<p2.snd) { minu(ogrpra, p1.fst); } else { maxu(ogrlew, p1.fst); } } else if(p1.fst < p2.fst) { ld a=(p2.snd-p1.snd)/(p2.fst-p1.fst); dol.pbp(a, p1.snd-a*p1.fst); } else { ld a=(p2.snd-p1.snd)/(p2.fst-p1.fst); gor.pbp(a, p1.snd-a*p1.fst); } } //debug(dol); //debug(gor); sort(dol.begin(), dol.end(), dol_cmp); sort(gor.begin(), gor.end(), gor_cmp); //debug(dol); //debug(gor); { auto tmp=gor; gor.clear(); int it=0; while(it<sz(tmp)) { while(it+1<sz(tmp) && tmp[it].fst==tmp[it+1].fst) it++; gor.pb(tmp[it]); it++; } } { auto tmp=dol; dol.clear(); int it=0; while(it<sz(tmp)) { while(it+1<sz(tmp) && tmp[it].fst==tmp[it+1].fst) it++; dol.pb(tmp[it]); it++; } } //debug(dol); //debug(gor); ld inf=1e10; vector <pair <ld, PLL> > odol; odol.pbp(-inf, dol[0]); { int it=1; while(it<sz(dol)) { ld pnt=przec(BOTH(odol.back().snd), BOTH(dol[it])); while(pnt<=odol.back().fst) { odol.pop_back(); pnt=przec(BOTH(odol.back().snd), BOTH(dol[it])); } odol.pbp(pnt, dol[it]); it++; } } vector <pair <ld, PLL> > ogor; ogor.pbp(-inf, gor[0]); { int it=1; while(it<sz(gor)) { ld pnt=przec(BOTH(ogor.back().snd), BOTH(gor[it])); while(pnt<=ogor.back().fst) { ogor.pop_back(); pnt=przec(BOTH(ogor.back().snd), BOTH(gor[it])); } ogor.pbp(pnt, gor[it]); it++; } } //debug(ogor); //debug(odol); //debug(ogrlew); //debug(ogrpra); vector <pair <ld, int> > eves; ITER(i, ogor) { eves.pbp(i.fst, 0); } ITER(i, odol) { eves.pbp(i.fst, 1); } eves.pbp(ogrlew, 2); eves.pbp(ogrpra, 3); sort(eves.begin(), eves.end()); bool bylo_lewo=0; bool bylo_prawo=0; ld last=-inf; ld wyn=0; int it1=-1; int it2=-1; //debug(eves); ITER(&eve, eves) { //debug(eve); int typ=eve.snd; ld akt=eve.fst; if(bylo_lewo) //ZLICZAJ { ld dod=pole(BOTH(ogor[it1].snd), BOTH(odol[it2].snd), last, akt); //debug("DODAJ", last, akt, it1, it2, dod); wyn=wyn+dod; } if(typ==0) { it1++; } if(typ==1) { it2++; } if(typ==2) { bylo_lewo=1; } if(typ==3) { bylo_prawo=1; } last=akt; if(bylo_prawo) break; } printf("%.20Lf\n", wyn.v); }
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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | #include <bits/stdc++.h> using namespace std; #define pb push_back #define BP push_back #define mp make_pair #define MP make_pair #define pbp(a, b) pb(mp(a, b)) #define PBP(a, b) PB(MP(a, b)) #define fst first #define snd second #define int4 int32_t #define LL long long #define int LL #define FOR(i,a,b) for(int(i)=(a)-(int)((a)>(b));(i)!=(b)-(int)((a)>(b));(i)+=((a)<(b))?1:-1) #define REP(b) FOR(i, 0, b) #define REPI(i, b) FOR(i, 0, b) #define REP1(b) FOR(i, 1, (b)+1) #define REPI1(i, b) FOR(i, 1, (b)+1) #define REV(b) FOR(i, b, 0) #define REV1(b) FOR(i, (b)+1, 1) #define ITER(j, b) for(auto (j) : (b)) #define ALL(x) (x).begin(), (x).end() #define BOTH(x) (x).fst, (x).snd #define sz(x) ((int)(x).size()) #define SZ(x) ((int)(x).size()) #define SKP(...) (__VA_ARGS__) typedef vector<int> VI; typedef pair<int,int> PII; typedef long double LD; template<class C> void minu(C& a4, C b4) { a4 = min(a4, b4); } template<class C> void maxu(C& a4, C b4) { a4 = max(a4, b4); } template<class TH> void _dbg(const char *sdbg, TH h) { while(*sdbg==' ') sdbg++; if(*sdbg!='\"' && *sdbg!='\'' && (*sdbg!='S' || *(sdbg+1)!='K' || *(sdbg+2)!='P'))cerr<<" "<<sdbg<<"="<<h<<"\n"; else cerr<<" "<<h<<"\n"; } template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg==' ') sdbg++; if(*sdbg!='\"' && *sdbg!='\'' && (*sdbg!='S' || *(sdbg+1)!='K' || *(sdbg+2)!='P')) { cerr<<" "; while(*sdbg!=',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, a...); } else { while(*sdbg!=',') sdbg++; cerr<<" "<<h<<","; _dbg(sdbg+1, a...); } } template<class T> ostream &operator<<(ostream &os, vector<T> V) { os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]"; } template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.fst << "," << P.snd << ")"; } int XXXX_XXXX_XXXX; #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define deb(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define scanf(...) (XXXX_XXXX_XXXX=scanf(__VA_ARGS__)) #else #define debug(...) {} #define cerr if(0)cout #endif struct XX_ld { LD v; XX_ld(LD V) : v(V) {} }; typedef XX_ld ld; LD eps=1e-11; inline ld operator +(ld a, ld b) { return ld(a.v+b.v); } inline ld operator -(ld a, ld b) { return ld(a.v-b.v); } inline ld operator -(ld a) { return ld(-a.v); } inline ld operator *(ld a, ld b) { return ld(a.v*b.v); } inline ld operator /(ld a, ld b) { return ld(a.v/b.v); } inline bool operator ==(ld a, ld b) { return a.v+eps >= b.v && a.v-eps <= b.v; } inline bool operator <(ld a, ld b) { return a.v <= b.v && !(a == b); } inline bool operator >(ld a, ld b) { return a.v >= b.v && !(a == b); } inline bool operator <=(ld a, ld b) { return a.v <= b.v || (a == b); } inline bool operator >=(ld a, ld b) { return a.v >= b.v || (a == b); } typedef pair <ld, ld> PLL; int strona(PLL &a, PLL &b, PLL &c) { ld tmp=a.fst*b.snd+b.fst*c.snd+c.fst*a.snd-(a.fst*c.snd+b.fst*a.snd+c.fst*b.snd); if(tmp>0) return -1; if(tmp<0) return 1; return 0; } ostream &operator<<(ostream &os, ld &b) { return os << b.v; } bool gor_cmp(PLL a, PLL b) { return mp(-a.fst.v, -a.snd.v) < mp(-b.fst.v, -b.snd.v); } bool dol_cmp(PLL a, PLL b) { return mp(a.fst.v, a.snd.v) < mp(b.fst.v, b.snd.v); } ld przec(ld a1, ld b1, ld a2, ld b2) { return (b2-b1)/(a1-a2); } ld pole(ld a1, ld b1, ld a2, ld b2, ld poc, ld kon) //1 to gora, 2 to dol { //deb(a1, b1, a2, b2, poc, kon); if(poc>=kon) return 0; ld p1=a1*poc+b1; ld k1=a1*kon+b1; ld p2=a2*poc+b2; ld k2=a2*kon+b2; if(p1>=p2 && k1>=k2) { //deb("oba", p1, k1, p2, k2, SKP((kon-poc)*((p1-p2)+(k1-k2))/2)); return (kon-poc)*((p1-p2)+(k1-k2))/2; } if(p1>=p2) { kon=przec(a1, b1, a2, b2); //deb("pie", p1, k1, p2, k2, kon, SKP((kon-poc)*((p1-p2)+(k1-k2))/2)); return (kon-poc)*(p1-p2)/2; } if(k1>=k2) { poc=przec(a1, b1, a2, b2); //deb("dru", p1, k1, p2, k2, poc, SKP((kon-poc)*((p1-p2)+(k1-k2))/2)); return (kon-poc)*(k1-k2)/2; } //deb(p1, k1, p2, k2); return 0; } int32_t main() { int n; scanf("%lld", &n); vector <pair <PLL, PLL> > pary; vector <pair <PLL, int> > wieze; REP(n) { int a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d); auto p1=mp(a, b), p2=mp(c, d); pary.pb(mp(p1, p2)); wieze.pb(mp(p1, i)); wieze.pb(mp(p2, i)); } vector <pair <PLL, PLL> > ogr; REP(sz(wieze)) { REPI(j, sz(wieze)) { if(i!=j) { int str[n]; FOR(x, 0, n) str[x]=0; bool nicprawo=1; ITER(w, wieze) { //debug(i, j, wieze[i].fst, wieze[j].fst, w.fst, SKP(strona(wieze[i].fst, wieze[j].fst, w.fst))); str[w.snd]+=strona(wieze[i].fst, wieze[j].fst, w.fst); if(str[w.snd]==2) nicprawo=0; } if(nicprawo) { ogr.pbp(wieze[i].fst, wieze[j].fst); } } } } //debug(ogr); ld ogrlew=-1000000; ld ogrpra=1000000; vector <PLL> gor, dol; ITER(par, ogr) { auto p1=par.fst, p2=par.snd; //debug(par); if(p1.fst==p2.fst) { if(p1.snd<p2.snd) { minu(ogrpra, p1.fst); } else { maxu(ogrlew, p1.fst); } } else if(p1.fst < p2.fst) { ld a=(p2.snd-p1.snd)/(p2.fst-p1.fst); dol.pbp(a, p1.snd-a*p1.fst); } else { ld a=(p2.snd-p1.snd)/(p2.fst-p1.fst); gor.pbp(a, p1.snd-a*p1.fst); } } //debug(dol); //debug(gor); sort(dol.begin(), dol.end(), dol_cmp); sort(gor.begin(), gor.end(), gor_cmp); //debug(dol); //debug(gor); { auto tmp=gor; gor.clear(); int it=0; while(it<sz(tmp)) { while(it+1<sz(tmp) && tmp[it].fst==tmp[it+1].fst) it++; gor.pb(tmp[it]); it++; } } { auto tmp=dol; dol.clear(); int it=0; while(it<sz(tmp)) { while(it+1<sz(tmp) && tmp[it].fst==tmp[it+1].fst) it++; dol.pb(tmp[it]); it++; } } //debug(dol); //debug(gor); ld inf=1e10; vector <pair <ld, PLL> > odol; odol.pbp(-inf, dol[0]); { int it=1; while(it<sz(dol)) { ld pnt=przec(BOTH(odol.back().snd), BOTH(dol[it])); while(pnt<=odol.back().fst) { odol.pop_back(); pnt=przec(BOTH(odol.back().snd), BOTH(dol[it])); } odol.pbp(pnt, dol[it]); it++; } } vector <pair <ld, PLL> > ogor; ogor.pbp(-inf, gor[0]); { int it=1; while(it<sz(gor)) { ld pnt=przec(BOTH(ogor.back().snd), BOTH(gor[it])); while(pnt<=ogor.back().fst) { ogor.pop_back(); pnt=przec(BOTH(ogor.back().snd), BOTH(gor[it])); } ogor.pbp(pnt, gor[it]); it++; } } //debug(ogor); //debug(odol); //debug(ogrlew); //debug(ogrpra); vector <pair <ld, int> > eves; ITER(i, ogor) { eves.pbp(i.fst, 0); } ITER(i, odol) { eves.pbp(i.fst, 1); } eves.pbp(ogrlew, 2); eves.pbp(ogrpra, 3); sort(eves.begin(), eves.end()); bool bylo_lewo=0; bool bylo_prawo=0; ld last=-inf; ld wyn=0; int it1=-1; int it2=-1; //debug(eves); ITER(&eve, eves) { //debug(eve); int typ=eve.snd; ld akt=eve.fst; if(bylo_lewo) //ZLICZAJ { ld dod=pole(BOTH(ogor[it1].snd), BOTH(odol[it2].snd), last, akt); //debug("DODAJ", last, akt, it1, it2, dod); wyn=wyn+dod; } if(typ==0) { it1++; } if(typ==1) { it2++; } if(typ==2) { bylo_lewo=1; } if(typ==3) { bylo_prawo=1; } last=akt; if(bylo_prawo) break; } printf("%.20Lf\n", wyn.v); } |