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
| #include<bits/stdc++.h> using namespace std; typedef long long ll;
typedef pair<int,int>pii; #define ff first #define ss second #define debug(x) std:: cerr << #x << " = " << x << std::endl; const int maxn=2e5+10,inf=0x3f3f3f3f,mod=1000000007; const ll INF=0x3f3f3f3f3f3f3f3f; const int MAXN = 100000; const double EPS = 1e-8; inline bool dcmp(double x, double y = 0) { return fabs(x - y) <= EPS; } typedef struct Vec {
double x, y; Vec(double x = 0, double y = 0) : x(x), y(y) {} Vec operator+(const Vec &v) const { return Vec(x + v.x, y + v.y); } Vec operator-(const Vec &v) const { return Vec(x - v.x, y - v.y); } Vec operator*(double d) const { return Vec(x * d, y * d); } Vec operator/(const double d) const { return Vec(x / d, y / d); } double norm() const { return x * x + y * y; } } Pt;
double dot(const Vec &a, const Vec &b) { return a.x * b.x + a.y * b.y; }
double cross(const Vec &a, const Vec &b) { return a.x * b.y - a.y * b.x; } struct Seg { Pt a, b; Seg(const Pt &a, const Pt &b) : a(a), b(b) {} bool include(const Pt &p) { return dcmp(cross(a - p, b - p)) && dot(a - p, b - p) <= 0; } double get_distance(Pt p, Pt A, Pt B) { Pt Ap, Ab, Bp; Ap.x = p.x - A.x, Ap.y = p.y - A.y; Ab.x = B.x - A.x, Ab.y = B.y - A.y; Bp.x = p.x - B.x, Bp.y = p.y - B.y; double r = (Ap.x*Ab.x + Ap.y*Ab.y)*1.0 / (Ab.x*Ab.x + Ab.y*Ab.y); if (r <= 0)return sqrt(Ap.x*Ap.x*1.0 + Ap.y*Ap.y); if (r >= 1)return sqrt(Bp.x*Bp.x*1.0+Bp.y*Bp.y); double px = A.x + Ab.x*r; double py = A.y + Ab.y*r; return sqrt((p.x-px)*(p.x-px)+(p.y-py)*(p.y-py)); } double dis(const Pt &p) { return get_distance(p,a,b); } }; struct Line { Pt a, b; Line() {} Line(const Pt &a, const Pt &b) : a(a), b(b) {} bool include(const Pt &p) const { return dcmp(cross(a - p, b - p)); } int relation(const Line &y) { if (include(y.a) && include(y.b)) return -1; else if (dcmp(cross(b - a, y.b - y.a))) return 0; else return 1; } Pt intersect(const Line &y) { double s1 = cross(y.a - a, y.b - a), s2 = cross(y.b - b, y.a - b); return a + (b - a) * s1 / (s1 + s2); } };
int n; Pt a[MAXN + 1];
inline bool compare(const Pt &a, const Pt &b) { Vec va = a - ::a[1], vb = b - ::a[1]; double t = cross(va, vb); if (!dcmp(t)) return t > 0; else return va.norm() < vb.norm(); } struct Poly { std::vector<Pt> pts; bool include(const Pt &p) const { int cnt = 0; for (size_t i = 0; i < pts.size(); i++) { const Pt &a = pts[i], &b = pts[(i + 1) % pts.size()]; if (Seg(a, b).include(p)) return true; double d1 = a.y - p.y, d2 = b.y - p.y, tmp = cross(a - p, b - p); if ((tmp >= 0 && d1 >= 0 && d2 < 0) || (tmp <= 0 && d1 < 0 && d2 >= 0)) cnt++; } return cnt % 2 == 1; } double area() const { double res = 0; for (size_t i = 0; i < pts.size(); i++) { const Pt &a = pts[i], &b = pts[(i + 1) % pts.size()]; res += cross(a, b); } return res / 2; } void convex() { int id = 1; for (int i = 1; i <= n; i++) { if (a[i].x < a[id].x || (a[i].x == a[id].x && a[i].y < a[id].y)) id = i; } if (id != 1) std::swap(a[1], a[id]); std::sort(a + 2, a + n + 1, &compare); pts.push_back(a[1]); for (int i = 2; i <= n; i++) { while (pts.size() >= 2 && cross(a[i] - pts[pts.size() - 2], pts.back() - pts[pts.size() - 2]) >= 0) pts.pop_back(); pts.push_back(a[i]); } } }; signed main(signed argc, char const *argv[]) { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #ifdef DEBUG freopen("input.in", "r", stdin); #endif
return 0; }
|