booljudge(int a, int b, int c){ returnsgn(p[a] - p[b] ^ p[c] - p[b]) >= 0; }
voidgetcircles(){ int k = 0; for (int i = 1; i <= n; i++) { Vec a = {cos(theta[i]), sin(theta[i])}, b = {-a.y, a.x}; a *= w/2 - r, b *= h/2 - r; p[++k] = q[i] + a + b; p[++k] = q[i] + a - b; p[++k] = q[i] - a + b; p[++k] = q[i] - a - b; } }
doubleandrew(){ staticint stk[N<<2]; double ans = 0; int tp = -1; n <<= 2; sort(p+1, p+1+n); for (int i = 1; i <= n; i++) { while (tp > 0 && judge(stk[tp-1], stk[tp], i)) tp--; stk[++tp] = i; } for (; tp; tp--) ans += (p[stk[tp]] - p[stk[tp-1]]).len();
tp = -1; for (int i = n; i; i--) { while (tp > 0 && judge(stk[tp-1], stk[tp], i)) tp--; stk[++tp] = i; } for (; tp; tp--) ans += (p[stk[tp]] - p[stk[tp-1]]).len();
return ans; }
intmain(){ scanf("%d%lf%lf%lf", &n, &h, &w, &r); for (int i = 1; i <= n; i++) scanf("%lf%lf%lf", &q[i].x, &q[i].y, &theta[i]); getcircles(); return !printf("%.2lf\n", andrew() + 2 * pi * r); }
[HAOI2011] 防线修建
给定点 n,x,y 表示 (0,0),(0,n),(x,y) 初始三个点,再给 m 个点 (xi,yi),初始所有点都在上凸包中。
voidupd(Vec a, Vec b, int fac){ if (a.lim || b.lim) return; now += fac * len(a-b); }
booljudge(Vec a, Vec b, Vec c){ returnsgn(a - b ^ c - b) <= 0; }
voidins(Vec v){ s.insert(v); auto it = s.find(v), pre = prev(it), nxt = next(it); if (judge(*pre, *it, *nxt)) return s.erase(it), void(); upd(*pre, *nxt, -1), upd(*pre, *it, 1), upd(*it, *nxt, 1); while (pre != s.begin()) { auto ppre = prev(pre); if (!judge(*ppre, *pre, *it)) break; upd(*ppre, *pre, -1), upd(*it, *pre, -1), upd(*ppre, *it, 1); s.erase(pre); pre = ppre; } while (nxt != prev(s.end())) { auto nnxt = next(nxt); if (!judge(*it, *nxt, *nnxt)) break; upd(*nnxt, *nxt, -1), upd(*it, *nxt, -1), upd(*nnxt, *it, 1); s.erase(nxt); nxt = nnxt; } }
signedmain(){ int x, y; scanf("%d%d%d%d", &n, &x, &y, &m); for (int i = 1; i <= m; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
scanf("%d", &q); for (int i = 1; i <= q; i++) { scanf("%d", &qry[i].typ); if (qry[i].typ == 1) { scanf("%d", &qry[i].u); del[qry[i].u] = true; } }
s.insert({-1e10, -1e100, true}), s.insert({1e10, -1e100, true}); ins({0, 0}), ins({1.0 * n, 0}), ins({1.0 * x, 1.0 * y}); for (int i = 1; i <= m; i++) if (!del[i]) ins(p[i]);
staticdouble stk[N]; int tp = 0; for (int i = q; i; i--) { if (qry[i].typ == 1) ins(p[qry[i].u]); else stk[++tp] = now; } while (tp) printf("%.2lf\n", stk[tp--]); return0; }