#include <bits/stdc++.h> #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define all(v) (v).begin(),(v).end() #define PII pair<int,int> #define mp make_pair #define st first #define nd second #define pb push_back #define lint long long int #define VI vector<int> #define debug(x) {cout <<#x <<" = " <<x <<endl; } #define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } #define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } #define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }} #define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }} #define make( x) int (x); scanf("%d",&(x)); #define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y)); #define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z)); #define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t)); #define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} #define IOS ios_base::sync_with_stdio(0) #define HEAP priority_queue #define read( x) scanf("%d",&(x)); #define read2( x, y) scanf("%d%d",&(x),&(y)); #define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z)); #define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t)); #define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);} #define jeb() fflush(stdout); using namespace std; const int max_n = 3e5 + 5; #define PDD pair<long double,long double> int n; PII g[1005]; vector<PII> hp; int ccw(int a, int b, int c) { PII p1 = {g[a].st-g[b].st, g[a].nd-g[b].nd}; PII p2 = {g[c].st-g[b].st, g[c].nd-g[b].nd}; return p1.st*p2.nd - p1.nd*p2.st; } bool check(int a, int b) { FOR(i,0,n) { if (ccw(a,b,i) < 0 && ccw(a,b,n+i) < 0) return false; } return true; } inline bool left(PII a, PII b, PII c) { return (b.st-a.st) * (c.nd-a.nd) - (c.st - a.st) * (b.nd - a.nd) <= 0; } vector<PII> hull; void add_point(PII pt, int limit) { while (hull.size() > limit && left(hull[hull.size()-2], hull[hull.size()-1],pt)) hull.pop_back(); hull.pb(pt); } vector<PDD> cur; PDD przeciecie(PII p1, PII p2, PDD q1, PDD q2) { long double det = (p1.st-p2.st)*1.*(q1.nd-q2.nd) - (p1.nd-p2.nd)*1.*(q1.st-q2.st); long double d1 = p1.st*p2.nd - p1.nd*p2.st; long double d2 = q1.st*q2.nd - q1.nd*q2.st; PDD res = { (d1*(q1.st-q2.st) - (p1.st-p2.st)*d2)*1./det, (d1*(q1.nd-q2.nd) - (p1.nd-p2.nd)*d2)*1./det}; return res; } bool inside(PII a, PII b, PDD c) { return (b.st-a.st) * (c.nd-a.nd) - (c.st - a.st) * (b.nd - a.nd) <= 1e-8; } double S() { double res = 0.; int m = cur.size(); FOR(i,0,cur.size()) { res += (cur[i].st * cur[(i+1)%m].nd - cur[(i+1)%m].st*cur[i].nd); } return max(res,-res)*0.5; } bool rowne(double ans1, double ans2) { double diff = abs(ans2 - ans1); if (diff < max(1., ans1) *1e-8) return true; return false; } double get_ans() { cur.clear(); FORE(i, hull) cur.pb(*i); random_shuffle(all(hp)); FOR(i,0,hp.size()) { PII p1 = g[hp[i].st]; PII p2 = g[hp[i].nd]; vector<PDD> dupa; FOR(j,0,cur.size()) { PDD q1 = cur[j]; PDD q2 = cur[(j+1)%cur.size()]; bool in1 = inside(p1,p2,q1); bool in2 = inside(p1,p2,q2); if (in1 && !in2) { if (!dupa.size() || dupa.back()!=q1) dupa.pb(q1); PDD XXX = przeciecie(p1,p2,q1,q2); if (!dupa.size() || dupa.back()!=XXX) dupa.pb(XXX); } else if (!in1 && !in2) { continue; } else if (!in1 && in2) { PDD XXX = przeciecie(p1,p2,q1,q2); if (!dupa.size() || dupa.back()!=XXX) dupa.pb(XXX); } else { if (!dupa.size() || dupa.back()!=q1) dupa.pb(q1); } } if (dupa.size() <= 2) { return 0.; } cur = dupa; } /* FORE(i, cur) { debug2(i->st, i->nd); }*/ return S(); } int main() { srand(time(NULL)); read(n); FOR(i,0,n) { make4(a,b,c,d); g[i] = {a,b}; g[i+n] = {c,d}; } FOR(i,0,2*n) FOR(j,0,2*n) { if (i == j) continue; if (check(i,j)) hp.pb({i,j}); } /* FORE(i,hp) { debug2(g[i->st].st, g[i->st].nd); debug2(g[i->nd].st, g[i->nd].nd); cout << endl; }*/ bool jedna_linia = true; FOR(i,2,2*n) { if (ccw(0,1,i) != 0) jedna_linia = false; } if (jedna_linia) { printf("%.17lf\n",0.); return 0; } vector<PII> in; FOR(i,0,2*n) in.pb(g[i]); sort(all(in)); FOR(i,0,in.size()) add_point(in[i], 1); int cursize = hull.size(); FORD(i, in.size()-1, 0) add_point(in[i], cursize); hull.pop_back(); printf("%.17lf\n", get_ans()); }
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 | #include <bits/stdc++.h> #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define all(v) (v).begin(),(v).end() #define PII pair<int,int> #define mp make_pair #define st first #define nd second #define pb push_back #define lint long long int #define VI vector<int> #define debug(x) {cout <<#x <<" = " <<x <<endl; } #define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } #define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } #define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }} #define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }} #define make( x) int (x); scanf("%d",&(x)); #define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y)); #define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z)); #define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t)); #define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} #define IOS ios_base::sync_with_stdio(0) #define HEAP priority_queue #define read( x) scanf("%d",&(x)); #define read2( x, y) scanf("%d%d",&(x),&(y)); #define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z)); #define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t)); #define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);} #define jeb() fflush(stdout); using namespace std; const int max_n = 3e5 + 5; #define PDD pair<long double,long double> int n; PII g[1005]; vector<PII> hp; int ccw(int a, int b, int c) { PII p1 = {g[a].st-g[b].st, g[a].nd-g[b].nd}; PII p2 = {g[c].st-g[b].st, g[c].nd-g[b].nd}; return p1.st*p2.nd - p1.nd*p2.st; } bool check(int a, int b) { FOR(i,0,n) { if (ccw(a,b,i) < 0 && ccw(a,b,n+i) < 0) return false; } return true; } inline bool left(PII a, PII b, PII c) { return (b.st-a.st) * (c.nd-a.nd) - (c.st - a.st) * (b.nd - a.nd) <= 0; } vector<PII> hull; void add_point(PII pt, int limit) { while (hull.size() > limit && left(hull[hull.size()-2], hull[hull.size()-1],pt)) hull.pop_back(); hull.pb(pt); } vector<PDD> cur; PDD przeciecie(PII p1, PII p2, PDD q1, PDD q2) { long double det = (p1.st-p2.st)*1.*(q1.nd-q2.nd) - (p1.nd-p2.nd)*1.*(q1.st-q2.st); long double d1 = p1.st*p2.nd - p1.nd*p2.st; long double d2 = q1.st*q2.nd - q1.nd*q2.st; PDD res = { (d1*(q1.st-q2.st) - (p1.st-p2.st)*d2)*1./det, (d1*(q1.nd-q2.nd) - (p1.nd-p2.nd)*d2)*1./det}; return res; } bool inside(PII a, PII b, PDD c) { return (b.st-a.st) * (c.nd-a.nd) - (c.st - a.st) * (b.nd - a.nd) <= 1e-8; } double S() { double res = 0.; int m = cur.size(); FOR(i,0,cur.size()) { res += (cur[i].st * cur[(i+1)%m].nd - cur[(i+1)%m].st*cur[i].nd); } return max(res,-res)*0.5; } bool rowne(double ans1, double ans2) { double diff = abs(ans2 - ans1); if (diff < max(1., ans1) *1e-8) return true; return false; } double get_ans() { cur.clear(); FORE(i, hull) cur.pb(*i); random_shuffle(all(hp)); FOR(i,0,hp.size()) { PII p1 = g[hp[i].st]; PII p2 = g[hp[i].nd]; vector<PDD> dupa; FOR(j,0,cur.size()) { PDD q1 = cur[j]; PDD q2 = cur[(j+1)%cur.size()]; bool in1 = inside(p1,p2,q1); bool in2 = inside(p1,p2,q2); if (in1 && !in2) { if (!dupa.size() || dupa.back()!=q1) dupa.pb(q1); PDD XXX = przeciecie(p1,p2,q1,q2); if (!dupa.size() || dupa.back()!=XXX) dupa.pb(XXX); } else if (!in1 && !in2) { continue; } else if (!in1 && in2) { PDD XXX = przeciecie(p1,p2,q1,q2); if (!dupa.size() || dupa.back()!=XXX) dupa.pb(XXX); } else { if (!dupa.size() || dupa.back()!=q1) dupa.pb(q1); } } if (dupa.size() <= 2) { return 0.; } cur = dupa; } /* FORE(i, cur) { debug2(i->st, i->nd); }*/ return S(); } int main() { srand(time(NULL)); read(n); FOR(i,0,n) { make4(a,b,c,d); g[i] = {a,b}; g[i+n] = {c,d}; } FOR(i,0,2*n) FOR(j,0,2*n) { if (i == j) continue; if (check(i,j)) hp.pb({i,j}); } /* FORE(i,hp) { debug2(g[i->st].st, g[i->st].nd); debug2(g[i->nd].st, g[i->nd].nd); cout << endl; }*/ bool jedna_linia = true; FOR(i,2,2*n) { if (ccw(0,1,i) != 0) jedna_linia = false; } if (jedna_linia) { printf("%.17lf\n",0.); return 0; } vector<PII> in; FOR(i,0,2*n) in.pb(g[i]); sort(all(in)); FOR(i,0,in.size()) add_point(in[i], 1); int cursize = hull.size(); FORD(i, in.size()-1, 0) add_point(in[i], cursize); hull.pop_back(); printf("%.17lf\n", get_ans()); } |