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
| #include <bits/stdc++.h> #define STC static #define LD long double #define PII pair<int, int> using namespace std; const int N = 10000 + 5; const LD eps = 1e-18; struct Point { LD x, y; Point operator - (const Point &t) const { return {x - t.x, y - t.y}; } } ; int ans[N]; struct Line { Point st, ed; vector<int> id; LD angle() { return atan2(ed.y - st.y, ed.x - st.x); } } ; int cmp(LD x, LD y) { if (fabs(x - y) < eps) return 0; return x > y ? 1 : -1; } LD cross(Point x, Point y) { return x.x * y.y - y.x * x.y; } LD area(Point x, Point y, Point z) { return cross(y - x, z - x); } bool operator < (Line &x, Line &y) { LD a = x.angle(), b = y.angle(); if (!cmp(a, b)) return area(x.st, x.ed, y.ed) < 0; return a < b; } Point jiao(Point p, Point u, Point q, Point v) { LD t = cross(v, p - q) / cross(u, v); return {p.x + u.x * t, p.y + u.y * t}; } Point jiao(Line x, Line y) { return jiao(x.st, x.ed - x.st, y.st, y.ed - y.st); } bool on_r(Line &x, Line y, Line z) { Point o = jiao(y, z); return cmp(area(x.st, x.ed, o), 0) < 0; } void halfp(Line x[], int len) { sort(x, x + len); int hh = 0, tt = -1; STC int q[N]; for (int i = 0; i < len; ++i) { if (i && !cmp(x[i].angle(), x[i - 1].angle())) continue; while (hh < tt && on_r(x[i], x[q[tt - 1]], x[q[tt]])) --tt; while (hh < tt && on_r(x[i], x[q[hh + 1]], x[q[hh]])) ++hh; q[++tt] = i; } while (hh < tt && on_r(x[q[hh]], x[q[tt - 1]], x[q[tt]])) --tt; while (hh < tt && on_r(x[q[tt]], x[q[hh + 1]], x[q[hh]])) ++hh; q[++tt] = q[hh]; int k = 0; for (int i = hh; i <= tt; ++i) for (auto id : x[q[i]].id) ans[k++] = id; sort(ans, ans + k); printf("%d\n", k); for (int i = 0; i < k; ++i) printf("%d ", ans[i]); } int main() { map<PII, vector<int> > ids; int n, cnt = 0; STC Line l[N]; STC int ki[N], vi[N]; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &ki[i]); for (int i = 1; i <= n; ++i) scanf("%d", &vi[i]); for (int i = 1; i <= n; ++i) ids[{ki[i], vi[i]}].push_back(i); l[cnt++] = {{0, N}, {0, 0}}; l[cnt++] = {{0, 0}, {N, 0}}; for (auto i : ids) l[cnt++] = {{0, i.first.first}, {1, i.first.first + i.first.second}, i.second}; halfp(l, cnt); return 0; }
|