//polowa kodu zarabana z mojego kodu //polowa z mojej biblioteczki acmowej (fork KTH) //polowa z jakiejs losowej strony w internecie (szukalem halfplanes) #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define eb emplace_back #define e1 first #define e2 second #define FOR(i, a, b) for (int i=(a); i<=(b); ++i) #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define OUT(x) {cout << x; exit(0); } typedef pair <long double, long double> PII; typedef pair <PII, int> PPI; typedef long double ll; PII tab[21]; PII hub[21]; int n; int wart[21], DL, DLE; int V; template <class T> struct Point { typedef Point P; T x, y; explicit Point(T x=0, T y=0) : x(x), y(y) {} bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); } bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); } P operator+(P p) const { return P(x+p.x, y+p.y); } P operator-(P p) const { return P(x-p.x, y-p.y); } P operator *(T d) const { return P(x*d, y*d); } P operator/(T d) const { return P(x/d, y/d); } T dot(P p) const { return x*p.x + y*p.y; } T cross(P p) const { return x*p.y - y*p.x; } T cross(P a, P b) const { return (a-* this).cross(b-* this); } T dist2() const { return x*x + y*y; } double dist() const { return sqrt((double)dist2()); } // angle to x−axis in interval [−pi , pi ] double angle() const { return atan2(y, x); } P unit() const { return * this/dist(); } // makes d i s t ()=1 P perp() const { return P(-y, x); } // rotates +90 degrees P normal() const { return perp().unit(); } // returns point rotated ’a ’ radians ccw around the origin P rotate(double a) const { return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); } }; typedef Point<double> P; const int R = 1024; vector <P> dr[2 * R + 5], vecz; int pot; inline ll det(PII &a, PII &b) { return (ll)a.e1 * b.e2 - (ll)a.e2 * b.e1; } inline ll area(PII &a, PII &b, PII &c) { return det(a, b) + det(b, c) + det(c, a); } typedef vector <int> vi; pair<vi, vi> ulHull(const vector<P>& S) { vi Q(sz(S)), U, L; iota(all(Q), 0); sort(all(Q), [&S](int a, int b){ return S[a] < S[b]; }); trav(it, Q) { #define ADDP(C, cmp) while (sz(C) > 1 && S[C[sz(C)-2]].cross(S[it], S[C.back()]) cmp 0) C.pop_back(); C.push_back(it); ADDP(U, <=); ADDP(L, >=); } return {U, L}; } vi convexHull(const vector<P>& S) { vi u, l; tie(u, l) = ulHull(S); if (sz(S) <= 1) return u; if (S[u[0]] == S[u[1]]) return {0}; l.insert(l.end(), u.rbegin()+1, u.rend()-1); return l; } vector <P> makeHull(vector <P> &poly) { vector <P> hull; vector <int> hl = convexHull(poly); trav(i, hl) hull.pb(poly[i]); return hull; } void solve(vector <P> vec, int zbior) { vector <P> hull = makeHull(vec); dr[zbior + pot] = hull; } #define MAX_SIZE 1000 const double PI = 2.0*acos(0.0); const double EPS = 1e-9; //too small/big????? struct PT { double x,y; double length() {return sqrt(x*x+y*y);} int normalize() // normalize the vector to unit length; return -1 if the vector is 0 { double l = length(); if(fabs(l)<EPS) return -1; x/=l; y/=l; return 0; } PT operator-(PT a) { PT r; r.x=x-a.x; r.y=y-a.y; return r; } PT operator+(PT a) { PT r; r.x=x+a.x; r.y=y+a.y; return r; } PT operator*(double sc) { PT r; r.x=x*sc; r.y=y*sc; return r; } }; bool operator<(const PT& a,const PT& b) { if(fabs(a.x-b.x)<EPS) return a.y<b.y; return a.x<b.x; } double dist(PT& a, PT& b) // the distance between two points { return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); } double dot(PT& a, PT& b) // the inner product of two vectors { return(a.x*b.x+a.y*b.y); } int sideSign(PT& p1,PT& p2,PT& p3) // which side is p3 to the line p1->p2? returns: 1 left, 0 on, -1 right { double sg = (p1.x-p3.x)*(p2.y-p3.y)-(p1.y - p3.y)*(p2.x-p3.x); if(fabs(sg)<EPS) return 0; if(sg>0)return 1; return -1; } bool better(PT& p1,PT& p2,PT& p3) // used by convec hull: from p3, if p1 is better than p2 { double sg = (p1.y - p3.y)*(p2.x-p3.x)-(p1.x-p3.x)*(p2.y-p3.y); //watch range of the numbers if(fabs(sg)<EPS) { if(dist(p3,p1)>dist(p3,p2))return true; else return false; } if(sg<0) return true; return false; } //convex hull nlogn void vex2(vector<PT> vin,vector<PT>& vout) // vin is not pass by reference, since we will rotate it { vout.clear(); int n=vin.size(); sort(vin.begin(),vin.end()); PT stk[MAX_SIZE]; int pstk, i; // hopefully more than 2 points stk[0] = vin[0]; stk[1] = vin[1]; pstk = 2; for(i=2; i<n; i++) { if(dist(vin[i], vin[i-1])<EPS) continue; while(pstk > 1 && better(vin[i], stk[pstk-1], stk[pstk-2])) pstk--; stk[pstk] = vin[i]; pstk++; } for(i=0; i<pstk; i++) vout.push_back(stk[i]); // turn 180 degree for(i=0; i<n; i++) { vin[i].y = -vin[i].y; vin[i].x = -vin[i].x; } sort(vin.begin(), vin.end()); stk[0] = vin[0]; stk[1] = vin[1]; pstk = 2; for(i=2; i<n; i++) { if(dist(vin[i], vin[i-1])<EPS) continue; while(pstk > 1 && better(vin[i], stk[pstk-1], stk[pstk-2])) pstk--; stk[pstk] = vin[i]; pstk++; } for(i=1; i<pstk-1; i++) { stk[i].x= -stk[i].x; // don’t forget rotate 180 d back. stk[i].y= -stk[i].y; vout.push_back(stk[i]); } } double trap(PT a, PT b) { return (0.5*(b.x - a.x)*(b.y + a.y)); } double triarea(PT a, PT b, PT c) { return fabs(trap(a,b)+trap(b,c)+trap(c,a)); } int pAndSeg(PT& p1, PT& p2, PT& p) // the relation of the point p and the segment p1->p2. // 1 if point is on the segment; 0 if not on the line; -1 if on the line but not on the segment { double s=triarea(p, p1, p2); if(s>EPS) return(0); double sg=(p.x-p1.x)*(p.x-p2.x); if(sg>EPS) return(-1); sg=(p.y-p1.y)*(p.y-p2.y); if(sg>EPS) return(-1); return(1); } void rotate(PT p0, PT p1, double a, PT& r) // rotate p1 around p0 clockwise, by angle a // don’t pass by reference for p1, so r and p1 can be the same { p1 = p1-p0; r.x = cos(a)*p1.x-sin(a)*p1.y; r.y = sin(a)*p1.x+cos(a)*p1.y; r = r+p0; } int pAndPoly(vector<PT> pv, PT p) // the relation of the point and the simple polygon // 1 if p is in pv; 0 outside; -1 on the polygon { int i, j; int n=pv.size(); pv.push_back(pv[0]); for(i=0;i<n;i++) if(pAndSeg(pv[i], pv[i+1], p)==1) return(-1); for(i=0;i<n;i++) pv[i] = pv[i]-p; p.x=p.y=0.0; double a, y; while(1) { a=(double)rand()/10000.00; j=0; for(i=0;i<n;i++) { rotate(p, pv[i], a, pv[i]); if(fabs(pv[i].x)<EPS) j=1; } if(j==0) { pv[n]=pv[0]; j=0; for(i=0;i<n;i++) if(pv[i].x*pv[i+1].x < -EPS) { y=pv[i+1].y-pv[i+1].x*(pv[i].y-pv[i+1].y)/(pv[i].x-pv[i+1].x); if(y>0) j++; } return(j%2); } } return 1; } int intersection( PT p1, PT p2, PT p3, PT p4, PT &r ) // two lines given by p1->p2, p3->p4 r is the intersection point // return -1 if two lines are parallel { double d = (p4.y - p3.y)*(p2.x-p1.x) - (p4.x - p3.x)*(p2.y - p1.y); if( fabs( d ) < EPS ) return -1; // might need to do something special!!! double ua, ub; ua = (p4.x - p3.x)*(p1.y-p3.y) - (p4.y-p3.y)*(p1.x-p3.x); ua /= d; // ub = (p2.x - p1.x)*(p1.y-p3.y) - (p2.y-p1.y)*(p1.x-p3.x); //ub /= d; r = p1 + (p2-p1)*ua; return 0; } int PInterP(vector<PT>& p1, vector<PT>& p2, vector<PT>& p3) { vector<PT> pts; PT pp; pts.clear(); int m=p1.size(); int n=p2.size(); int i, j; for(i=0;i<m;i++) if(pAndPoly(p2, p1[i])!=0) pts.push_back(p1[i]); for(i=0;i<n;i++) if(pAndPoly(p1, p2[i])!=0) pts.push_back(p2[i]); if(m>1 && n>1) for(i=0;i<m;i++) for(j=0;j<n;j++) if(intersection(p1[i], p1[(i+1)%m], p2[j], p2[(j+1)%n], pp)==0) { //cout<<i<<" "<<j<<" -> "<<pp.x<<" "<<pp.y<<endl; if(pAndSeg(p1[i], p1[(i+1)%m], pp)!=1) continue; if(pAndSeg(p2[j], p2[(j+1)%n], pp)!=1) continue; pts.push_back(pp); } if(pts.size()<=1) { p3.resize(1); p3[0].x=p3[0].y=0.0; return(1); } //show(pts); vex2(pts, p3); // or vex return(0); } void lineIntersection(const P& s1, const P& e1, const P& s2, const P& e2, P& r) { if ((e1-s1).cross(e2-s2)) { // i f not p a r a l l e l l r = s2-(e2-s2)*(e1-s1).cross(s2-s1)/(e1-s1).cross(e2-s2); } } vector<P> polygonCut(const vector<P> poly, P s, P e) { vector<P> res; rep(i,0,sz(poly)) { P cur = poly[i], prev = i ? poly[i-1] : poly.back(); bool side = s.cross(e, cur) < 0; if (side != (s.cross(e, prev) < 0)) { res.emplace_back(); lineIntersection(s, e, cur, prev, res.back()); } if (side) res.push_back(cur); } return res; } vector <P> intersect(vector <P> poly2, vector <P> poly1) { vector <PT> a, b, c; PT help; for (auto u : poly1) { help.x = u.x; help.y = u.y; a.pb(help); } for (auto u : poly2) { help.x = u.x; help.y = u.y; b.pb(help); } PInterP(a, b, c); vector <P> nowe; for (auto u : c) nowe.pb(P(u.x, u.y)); return nowe; } long double polygonArea2(vector<P>& v) { if (v.size() <= 2) return 0.0; long double a = v.back().cross(v[0]); rep(i,0,sz(v)-1) a += v[i].cross(v[i+1]); return a; } int main() { cin >> n; assert(n <= 10); FOR(i, 1, n) cin >> tab[i].e1 >> tab[i].e2 >> hub[i].e1 >> hub[i].e2; pot = (1 << n); for (int i=0; i<pot; ++i) { vecz.clear(); for (int j=0; j<n; ++j) if (i & (1 << j)) vecz.pb(P(tab[j + 1].e1, tab[j + 1].e2)); else vecz.pb(P(hub[j + 1].e1, hub[j + 1].e2)); solve(vecz, i); } for (int i = pot - 1; i > 0; --i) dr[i] = intersect(dr[2 * i], dr[2 * i + 1]); /*for (auto u : intersect(dr[pot], dr[2 * pot - 1])) cout << u.x << ' ' << u.y << endl; cout << endl; FOR(i, 1, 2 * pot - 1) cout << dr[i].size() <<' '; cout << endl; FOR(i, 0, 2) cout << dr[2 * pot - 1][i].x << ' ' << dr[2 * pot - 1][i].y << endl; * */ long double wyn = polygonArea2(dr[1]); wyn = abs(wyn) * 0.5; cout << fixed; cout << setprecision(13); cout << wyn; }
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 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | //polowa kodu zarabana z mojego kodu //polowa z mojej biblioteczki acmowej (fork KTH) //polowa z jakiejs losowej strony w internecie (szukalem halfplanes) #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define eb emplace_back #define e1 first #define e2 second #define FOR(i, a, b) for (int i=(a); i<=(b); ++i) #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define OUT(x) {cout << x; exit(0); } typedef pair <long double, long double> PII; typedef pair <PII, int> PPI; typedef long double ll; PII tab[21]; PII hub[21]; int n; int wart[21], DL, DLE; int V; template <class T> struct Point { typedef Point P; T x, y; explicit Point(T x=0, T y=0) : x(x), y(y) {} bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); } bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); } P operator+(P p) const { return P(x+p.x, y+p.y); } P operator-(P p) const { return P(x-p.x, y-p.y); } P operator *(T d) const { return P(x*d, y*d); } P operator/(T d) const { return P(x/d, y/d); } T dot(P p) const { return x*p.x + y*p.y; } T cross(P p) const { return x*p.y - y*p.x; } T cross(P a, P b) const { return (a-* this).cross(b-* this); } T dist2() const { return x*x + y*y; } double dist() const { return sqrt((double)dist2()); } // angle to x−axis in interval [−pi , pi ] double angle() const { return atan2(y, x); } P unit() const { return * this/dist(); } // makes d i s t ()=1 P perp() const { return P(-y, x); } // rotates +90 degrees P normal() const { return perp().unit(); } // returns point rotated ’a ’ radians ccw around the origin P rotate(double a) const { return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); } }; typedef Point<double> P; const int R = 1024; vector <P> dr[2 * R + 5], vecz; int pot; inline ll det(PII &a, PII &b) { return (ll)a.e1 * b.e2 - (ll)a.e2 * b.e1; } inline ll area(PII &a, PII &b, PII &c) { return det(a, b) + det(b, c) + det(c, a); } typedef vector <int> vi; pair<vi, vi> ulHull(const vector<P>& S) { vi Q(sz(S)), U, L; iota(all(Q), 0); sort(all(Q), [&S](int a, int b){ return S[a] < S[b]; }); trav(it, Q) { #define ADDP(C, cmp) while (sz(C) > 1 && S[C[sz(C)-2]].cross(S[it], S[C.back()]) cmp 0) C.pop_back(); C.push_back(it); ADDP(U, <=); ADDP(L, >=); } return {U, L}; } vi convexHull(const vector<P>& S) { vi u, l; tie(u, l) = ulHull(S); if (sz(S) <= 1) return u; if (S[u[0]] == S[u[1]]) return {0}; l.insert(l.end(), u.rbegin()+1, u.rend()-1); return l; } vector <P> makeHull(vector <P> &poly) { vector <P> hull; vector <int> hl = convexHull(poly); trav(i, hl) hull.pb(poly[i]); return hull; } void solve(vector <P> vec, int zbior) { vector <P> hull = makeHull(vec); dr[zbior + pot] = hull; } #define MAX_SIZE 1000 const double PI = 2.0*acos(0.0); const double EPS = 1e-9; //too small/big????? struct PT { double x,y; double length() {return sqrt(x*x+y*y);} int normalize() // normalize the vector to unit length; return -1 if the vector is 0 { double l = length(); if(fabs(l)<EPS) return -1; x/=l; y/=l; return 0; } PT operator-(PT a) { PT r; r.x=x-a.x; r.y=y-a.y; return r; } PT operator+(PT a) { PT r; r.x=x+a.x; r.y=y+a.y; return r; } PT operator*(double sc) { PT r; r.x=x*sc; r.y=y*sc; return r; } }; bool operator<(const PT& a,const PT& b) { if(fabs(a.x-b.x)<EPS) return a.y<b.y; return a.x<b.x; } double dist(PT& a, PT& b) // the distance between two points { return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); } double dot(PT& a, PT& b) // the inner product of two vectors { return(a.x*b.x+a.y*b.y); } int sideSign(PT& p1,PT& p2,PT& p3) // which side is p3 to the line p1->p2? returns: 1 left, 0 on, -1 right { double sg = (p1.x-p3.x)*(p2.y-p3.y)-(p1.y - p3.y)*(p2.x-p3.x); if(fabs(sg)<EPS) return 0; if(sg>0)return 1; return -1; } bool better(PT& p1,PT& p2,PT& p3) // used by convec hull: from p3, if p1 is better than p2 { double sg = (p1.y - p3.y)*(p2.x-p3.x)-(p1.x-p3.x)*(p2.y-p3.y); //watch range of the numbers if(fabs(sg)<EPS) { if(dist(p3,p1)>dist(p3,p2))return true; else return false; } if(sg<0) return true; return false; } //convex hull nlogn void vex2(vector<PT> vin,vector<PT>& vout) // vin is not pass by reference, since we will rotate it { vout.clear(); int n=vin.size(); sort(vin.begin(),vin.end()); PT stk[MAX_SIZE]; int pstk, i; // hopefully more than 2 points stk[0] = vin[0]; stk[1] = vin[1]; pstk = 2; for(i=2; i<n; i++) { if(dist(vin[i], vin[i-1])<EPS) continue; while(pstk > 1 && better(vin[i], stk[pstk-1], stk[pstk-2])) pstk--; stk[pstk] = vin[i]; pstk++; } for(i=0; i<pstk; i++) vout.push_back(stk[i]); // turn 180 degree for(i=0; i<n; i++) { vin[i].y = -vin[i].y; vin[i].x = -vin[i].x; } sort(vin.begin(), vin.end()); stk[0] = vin[0]; stk[1] = vin[1]; pstk = 2; for(i=2; i<n; i++) { if(dist(vin[i], vin[i-1])<EPS) continue; while(pstk > 1 && better(vin[i], stk[pstk-1], stk[pstk-2])) pstk--; stk[pstk] = vin[i]; pstk++; } for(i=1; i<pstk-1; i++) { stk[i].x= -stk[i].x; // don’t forget rotate 180 d back. stk[i].y= -stk[i].y; vout.push_back(stk[i]); } } double trap(PT a, PT b) { return (0.5*(b.x - a.x)*(b.y + a.y)); } double triarea(PT a, PT b, PT c) { return fabs(trap(a,b)+trap(b,c)+trap(c,a)); } int pAndSeg(PT& p1, PT& p2, PT& p) // the relation of the point p and the segment p1->p2. // 1 if point is on the segment; 0 if not on the line; -1 if on the line but not on the segment { double s=triarea(p, p1, p2); if(s>EPS) return(0); double sg=(p.x-p1.x)*(p.x-p2.x); if(sg>EPS) return(-1); sg=(p.y-p1.y)*(p.y-p2.y); if(sg>EPS) return(-1); return(1); } void rotate(PT p0, PT p1, double a, PT& r) // rotate p1 around p0 clockwise, by angle a // don’t pass by reference for p1, so r and p1 can be the same { p1 = p1-p0; r.x = cos(a)*p1.x-sin(a)*p1.y; r.y = sin(a)*p1.x+cos(a)*p1.y; r = r+p0; } int pAndPoly(vector<PT> pv, PT p) // the relation of the point and the simple polygon // 1 if p is in pv; 0 outside; -1 on the polygon { int i, j; int n=pv.size(); pv.push_back(pv[0]); for(i=0;i<n;i++) if(pAndSeg(pv[i], pv[i+1], p)==1) return(-1); for(i=0;i<n;i++) pv[i] = pv[i]-p; p.x=p.y=0.0; double a, y; while(1) { a=(double)rand()/10000.00; j=0; for(i=0;i<n;i++) { rotate(p, pv[i], a, pv[i]); if(fabs(pv[i].x)<EPS) j=1; } if(j==0) { pv[n]=pv[0]; j=0; for(i=0;i<n;i++) if(pv[i].x*pv[i+1].x < -EPS) { y=pv[i+1].y-pv[i+1].x*(pv[i].y-pv[i+1].y)/(pv[i].x-pv[i+1].x); if(y>0) j++; } return(j%2); } } return 1; } int intersection( PT p1, PT p2, PT p3, PT p4, PT &r ) // two lines given by p1->p2, p3->p4 r is the intersection point // return -1 if two lines are parallel { double d = (p4.y - p3.y)*(p2.x-p1.x) - (p4.x - p3.x)*(p2.y - p1.y); if( fabs( d ) < EPS ) return -1; // might need to do something special!!! double ua, ub; ua = (p4.x - p3.x)*(p1.y-p3.y) - (p4.y-p3.y)*(p1.x-p3.x); ua /= d; // ub = (p2.x - p1.x)*(p1.y-p3.y) - (p2.y-p1.y)*(p1.x-p3.x); //ub /= d; r = p1 + (p2-p1)*ua; return 0; } int PInterP(vector<PT>& p1, vector<PT>& p2, vector<PT>& p3) { vector<PT> pts; PT pp; pts.clear(); int m=p1.size(); int n=p2.size(); int i, j; for(i=0;i<m;i++) if(pAndPoly(p2, p1[i])!=0) pts.push_back(p1[i]); for(i=0;i<n;i++) if(pAndPoly(p1, p2[i])!=0) pts.push_back(p2[i]); if(m>1 && n>1) for(i=0;i<m;i++) for(j=0;j<n;j++) if(intersection(p1[i], p1[(i+1)%m], p2[j], p2[(j+1)%n], pp)==0) { //cout<<i<<" "<<j<<" -> "<<pp.x<<" "<<pp.y<<endl; if(pAndSeg(p1[i], p1[(i+1)%m], pp)!=1) continue; if(pAndSeg(p2[j], p2[(j+1)%n], pp)!=1) continue; pts.push_back(pp); } if(pts.size()<=1) { p3.resize(1); p3[0].x=p3[0].y=0.0; return(1); } //show(pts); vex2(pts, p3); // or vex return(0); } void lineIntersection(const P& s1, const P& e1, const P& s2, const P& e2, P& r) { if ((e1-s1).cross(e2-s2)) { // i f not p a r a l l e l l r = s2-(e2-s2)*(e1-s1).cross(s2-s1)/(e1-s1).cross(e2-s2); } } vector<P> polygonCut(const vector<P> poly, P s, P e) { vector<P> res; rep(i,0,sz(poly)) { P cur = poly[i], prev = i ? poly[i-1] : poly.back(); bool side = s.cross(e, cur) < 0; if (side != (s.cross(e, prev) < 0)) { res.emplace_back(); lineIntersection(s, e, cur, prev, res.back()); } if (side) res.push_back(cur); } return res; } vector <P> intersect(vector <P> poly2, vector <P> poly1) { vector <PT> a, b, c; PT help; for (auto u : poly1) { help.x = u.x; help.y = u.y; a.pb(help); } for (auto u : poly2) { help.x = u.x; help.y = u.y; b.pb(help); } PInterP(a, b, c); vector <P> nowe; for (auto u : c) nowe.pb(P(u.x, u.y)); return nowe; } long double polygonArea2(vector<P>& v) { if (v.size() <= 2) return 0.0; long double a = v.back().cross(v[0]); rep(i,0,sz(v)-1) a += v[i].cross(v[i+1]); return a; } int main() { cin >> n; assert(n <= 10); FOR(i, 1, n) cin >> tab[i].e1 >> tab[i].e2 >> hub[i].e1 >> hub[i].e2; pot = (1 << n); for (int i=0; i<pot; ++i) { vecz.clear(); for (int j=0; j<n; ++j) if (i & (1 << j)) vecz.pb(P(tab[j + 1].e1, tab[j + 1].e2)); else vecz.pb(P(hub[j + 1].e1, hub[j + 1].e2)); solve(vecz, i); } for (int i = pot - 1; i > 0; --i) dr[i] = intersect(dr[2 * i], dr[2 * i + 1]); /*for (auto u : intersect(dr[pot], dr[2 * pot - 1])) cout << u.x << ' ' << u.y << endl; cout << endl; FOR(i, 1, 2 * pot - 1) cout << dr[i].size() <<' '; cout << endl; FOR(i, 0, 2) cout << dr[2 * pot - 1][i].x << ' ' << dr[2 * pot - 1][i].y << endl; * */ long double wyn = polygonArea2(dr[1]); wyn = abs(wyn) * 0.5; cout << fixed; cout << setprecision(13); cout << wyn; } |