#include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point() { } Point(int _x, int _y): x(_x), y(_y) { } Point const operator-() const { return Point(-x, -y); } Point const operator-(Point const &rhs) const { return Point(x - rhs.x, y - rhs.y); } friend istream &operator>>(istream &is, Point &rhs) { return (is >> rhs.x >> rhs.y); } friend ostream &operator<<(ostream &os, Point const &rhs) { return (os << "(" << rhs.x << "," << rhs.y << ")"); } }; struct DPoint { double x, y; DPoint() { } DPoint(double _x, double _y): x(_x), y(_y) { } DPoint const operator-(DPoint const &rhs) const { return DPoint(x - rhs.x, y - rhs.y); } bool operator==(DPoint const &rhs) const { return x == rhs.x and y == rhs.y; } friend ostream &operator<<(ostream &os, DPoint const &rhs) { return (os << "(" << rhs.x << "," << rhs.y << ")"); } }; typedef Point Tower; struct Mage { Tower a, b; friend istream &operator>>(istream &is, Mage &rhs) { return (is >> rhs.a >> rhs.b); } }; typedef Point Vector; typedef DPoint DVector; template<typename T> int sgn(T const &x) { return (x == 0 ? 0 : (x < 0 ? -1 : 1)); } struct Line { Point p; Vector v; double angle; Line() { } Line(Point const &_p, Vector const &_v): p(_p), v(_v) { } void fix() { if(v.y < 0 or (v.y == 0 and v.x < 0)) v = -v; } int64_t ccw(Point const &r) const { return v.x * int64_t(p.y - r.y) - v.y * int64_t(p.x - r.x); } friend ostream &operator<<(ostream &os, Line const &rhs) { return (os << "Line[" << rhs.p << "+" << rhs.v << "*t]"); } }; struct DLine { DPoint p; DVector v; DLine() { } DLine(DPoint const &_p, DVector const &_v): p(_p), v(_v) { } int64_t ccw(DPoint const &r) const { return v.x * (p.y - r.y) - v.y * (p.x - r.x); } friend ostream &operator<<(ostream &os, DLine const &rhs) { return (os << "DLine[" << rhs.p << "+" << rhs.v << "*t]"); } }; void towersClash(vector<Mage> const &mages, Tower const &r, Tower const &t, vector<Line> &lines) { Line l(r, t - r); int side = 0; for(size_t i = 0; i < mages.size(); i++) { int sa = sgn(l.ccw(mages[i].a)); int sb = sgn(l.ccw(mages[i].b)); if(sa * sb <= 0) continue; if(side == 0) side = sa; if(side != sa) return; } if(side == -1) l.v = -l.v; if(side == 0) { cerr << "Should not happen.\n"; exit(1); } l.angle = atan2(l.v.y, l.v.x); lines.push_back(l); } void magesClash(vector<Mage> const &mages, Mage const &p, Mage const &q, vector<Line> &lines) { towersClash(mages, p.a, q.a, lines); towersClash(mages, p.a, q.b, lines); towersClash(mages, p.b, q.a, lines); towersClash(mages, p.b, q.b, lines); } bool v_equals(Vector const &v, Vector const &w) { return v.x * int64_t(w.y) == v.y * int64_t(w.x); } void filter(vector<Line> &lines) { vector<Line> newLines; size_t j = 0; for(size_t i = 1; i < lines.size(); i++) { if(v_equals(lines[j].v, lines[i].v)) { if(lines[j].ccw(lines[i].p) <= 0) { continue; } else if(lines[i].ccw(lines[j].p)) { j = i; } else { cout << "0.0\n"; exit(0); } } else { newLines.push_back(lines[j]); j = i; } } newLines.push_back(lines[j]); lines.swap(newLines); } template<typename T> void duplicate(vector<T> &vec) { int n = vec.size(); vec.reserve(2 * n); for(int i = 0; i < n; i++) vec.push_back(vec[i]); } DPoint intersection(Line const &k, Line const &l) { // t * (kvx) + u * (-lvx) = lpx - kpx // t * (kvy) + u * (-lvy) = lpy - kpy int64_t wm = k.v.x * int64_t(-l.v.y) - (-l.v.x) * int64_t(k.v.y); int64_t wt = (l.p.x - k.p.x) * int64_t(-l.v.y) - (-l.v.x) * int64_t(l.p.y - k.p.y); // int64_t wu = k.v.x * int64_t(-l.v.x) - (-l.v.x) * int64_t(k.v.y); double t = wt / double(wm); return DPoint(k.p.x + t * k.v.x, k.p.y + t * k.v.y); } int main() { #ifndef DEBUG ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif int n; cin >> n; vector<Mage> mages(n); for(int i = 0; i < n; i++) cin >> mages[i]; int x0 = mages[0].a.x; int x1 = mages[0].a.x; int y0 = mages[0].a.y; int y1 = mages[0].a.y; for(int i = 1; i < n; i++) { x0 = min(x0, mages[i].a.x); x1 = max(x1, mages[i].a.x); y0 = min(y0, mages[i].a.y); y1 = max(y1, mages[i].a.y); x0 = min(x0, mages[i].b.x); x1 = max(x1, mages[i].b.x); y0 = min(y0, mages[i].b.y); y1 = max(y1, mages[i].b.y); } double S = (y1 - y0) * (x1 - x0); cout << fixed << setprecision(12) << S * 0.1 << '\n'; return 0; }
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 | #include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point() { } Point(int _x, int _y): x(_x), y(_y) { } Point const operator-() const { return Point(-x, -y); } Point const operator-(Point const &rhs) const { return Point(x - rhs.x, y - rhs.y); } friend istream &operator>>(istream &is, Point &rhs) { return (is >> rhs.x >> rhs.y); } friend ostream &operator<<(ostream &os, Point const &rhs) { return (os << "(" << rhs.x << "," << rhs.y << ")"); } }; struct DPoint { double x, y; DPoint() { } DPoint(double _x, double _y): x(_x), y(_y) { } DPoint const operator-(DPoint const &rhs) const { return DPoint(x - rhs.x, y - rhs.y); } bool operator==(DPoint const &rhs) const { return x == rhs.x and y == rhs.y; } friend ostream &operator<<(ostream &os, DPoint const &rhs) { return (os << "(" << rhs.x << "," << rhs.y << ")"); } }; typedef Point Tower; struct Mage { Tower a, b; friend istream &operator>>(istream &is, Mage &rhs) { return (is >> rhs.a >> rhs.b); } }; typedef Point Vector; typedef DPoint DVector; template<typename T> int sgn(T const &x) { return (x == 0 ? 0 : (x < 0 ? -1 : 1)); } struct Line { Point p; Vector v; double angle; Line() { } Line(Point const &_p, Vector const &_v): p(_p), v(_v) { } void fix() { if(v.y < 0 or (v.y == 0 and v.x < 0)) v = -v; } int64_t ccw(Point const &r) const { return v.x * int64_t(p.y - r.y) - v.y * int64_t(p.x - r.x); } friend ostream &operator<<(ostream &os, Line const &rhs) { return (os << "Line[" << rhs.p << "+" << rhs.v << "*t]"); } }; struct DLine { DPoint p; DVector v; DLine() { } DLine(DPoint const &_p, DVector const &_v): p(_p), v(_v) { } int64_t ccw(DPoint const &r) const { return v.x * (p.y - r.y) - v.y * (p.x - r.x); } friend ostream &operator<<(ostream &os, DLine const &rhs) { return (os << "DLine[" << rhs.p << "+" << rhs.v << "*t]"); } }; void towersClash(vector<Mage> const &mages, Tower const &r, Tower const &t, vector<Line> &lines) { Line l(r, t - r); int side = 0; for(size_t i = 0; i < mages.size(); i++) { int sa = sgn(l.ccw(mages[i].a)); int sb = sgn(l.ccw(mages[i].b)); if(sa * sb <= 0) continue; if(side == 0) side = sa; if(side != sa) return; } if(side == -1) l.v = -l.v; if(side == 0) { cerr << "Should not happen.\n"; exit(1); } l.angle = atan2(l.v.y, l.v.x); lines.push_back(l); } void magesClash(vector<Mage> const &mages, Mage const &p, Mage const &q, vector<Line> &lines) { towersClash(mages, p.a, q.a, lines); towersClash(mages, p.a, q.b, lines); towersClash(mages, p.b, q.a, lines); towersClash(mages, p.b, q.b, lines); } bool v_equals(Vector const &v, Vector const &w) { return v.x * int64_t(w.y) == v.y * int64_t(w.x); } void filter(vector<Line> &lines) { vector<Line> newLines; size_t j = 0; for(size_t i = 1; i < lines.size(); i++) { if(v_equals(lines[j].v, lines[i].v)) { if(lines[j].ccw(lines[i].p) <= 0) { continue; } else if(lines[i].ccw(lines[j].p)) { j = i; } else { cout << "0.0\n"; exit(0); } } else { newLines.push_back(lines[j]); j = i; } } newLines.push_back(lines[j]); lines.swap(newLines); } template<typename T> void duplicate(vector<T> &vec) { int n = vec.size(); vec.reserve(2 * n); for(int i = 0; i < n; i++) vec.push_back(vec[i]); } DPoint intersection(Line const &k, Line const &l) { // t * (kvx) + u * (-lvx) = lpx - kpx // t * (kvy) + u * (-lvy) = lpy - kpy int64_t wm = k.v.x * int64_t(-l.v.y) - (-l.v.x) * int64_t(k.v.y); int64_t wt = (l.p.x - k.p.x) * int64_t(-l.v.y) - (-l.v.x) * int64_t(l.p.y - k.p.y); // int64_t wu = k.v.x * int64_t(-l.v.x) - (-l.v.x) * int64_t(k.v.y); double t = wt / double(wm); return DPoint(k.p.x + t * k.v.x, k.p.y + t * k.v.y); } int main() { #ifndef DEBUG ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif int n; cin >> n; vector<Mage> mages(n); for(int i = 0; i < n; i++) cin >> mages[i]; int x0 = mages[0].a.x; int x1 = mages[0].a.x; int y0 = mages[0].a.y; int y1 = mages[0].a.y; for(int i = 1; i < n; i++) { x0 = min(x0, mages[i].a.x); x1 = max(x1, mages[i].a.x); y0 = min(y0, mages[i].a.y); y1 = max(y1, mages[i].a.y); x0 = min(x0, mages[i].b.x); x1 = max(x1, mages[i].b.x); y0 = min(y0, mages[i].b.y); y1 = max(y1, mages[i].b.y); } double S = (y1 - y0) * (x1 - x0); cout << fixed << setprecision(12) << S * 0.1 << '\n'; return 0; } |