structCircle { /*@param x x of center O @param y y of center O @param R radius*/ longdouble x, y, R; /*@param l 最左端 @param r 最右端*/ longdouble l, r; /*按左端点排序 相同则按右端点排序*/ friendinlinebooloperator<(const Circle& a, const Circle& b) { return a.l < b.l - EPS; } } circle[MAXN];
structSeg { /*@param l 左端点 @param r 右端点*/ longdouble l, r; /*按左端点排序 相同则按右端点排序*/ friendinlinebooloperator<(const Seg& a, const Seg& b) { return a.l < b.l - EPS; } } seg[MAXN];
unordered_map<double, double> mp; inlinelongdoublef(longdouble x){ //算x处覆盖的线段总长 int tot = 0; for (auto& i : chosen) { longdouble tmp = pow(circle[i].R, 2) - pow(x - circle[i].x, 2); if (tmp < EPS) continue; seg[++tot].l = circle[i].y - sqrt(tmp); seg[tot].r = circle[i].y + sqrt(tmp); } sort(seg + 1, seg + tot + 1); longdouble l = seg[1].l, len = .0; for (int i = 1; i <= tot; i++) { l = max(l, seg[i].l); if (l < seg[i].r - EPS) len += seg[i].r - l; l = max(l, seg[i].r); } return len; }
structCircle { /*@param x x of center O @param y y of center O @param R radius*/ double x, y, R; /*@param l 最左端 @param r 最右端*/ double l, r; } circle[MAXN];
doubleintegral(double l, double r, double eps, double i){ double mid = (l + r) / 2; double iL = simpson(l, mid), iR = simpson(mid, r); if (fabs(iL + iR - i) <= eps * 15) return iL + iR + (iL + iR - i) / 15; return integral(l, mid, eps / 2, iL) + integral(mid, r, eps / 2, iR); }
inlinevoidinit(double res = 0){ sort(tri + 1, tri + n + 1); sort(posX.begin(), posX.end()); auto edIt = unique(posX.begin(), posX.end()); for (auto it = posX.begin() + 1; it != edIt; it++) { double l = *(it - 1), r = *(it); chosen.clear(); for (int i = 1; i <= n; i++) { if ((tri[i].x1 <= l && l <= tri[i].x2) || (tri[i].x1 <= r && r <= tri[i].x2)) { chosen.push_back(i); } } l += 2e-9, r -= 2e-9; res += integral(l, r, 1e-4, simpson(l, r)); } cout << setprecision(1) << fixed << res << endl; }
intmain(){ std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1, x, y, m; i <= n; i++) { cin >> x >> y >> m; tri[i].x1 = x, tri[i].y1 = y + m; tri[i].x2 = x + m, tri[i].y2 = y; posX.push_back(x), posX.push_back(x + m); } init(); return0; }
int n, x, y, m; vector<int> chosen, pos; bool vis[MAXN];
structTriangle { int x, y, x2, y2; friendinlinebooloperator<(const Triangle& a, const Triangle& b) { return a.x < b.x; } } tri[MAXN];
structSegment { longdouble l, r; friendbooloperator<(const Segment& a, const Segment& b) { return a.l < b.l; } } seg[MAXN];
unordered_map<longdouble, longdouble> mp; inlinelongdoublef(longdouble x){ if (mp.count(x)) return mp[x]; int tot = 0; for (auto& i : chosen) { if (x < (longdouble)tri[i].x - EPS || (longdouble)tri[i].x2 < x - EPS) continue; seg[++tot].l = (longdouble)tri[i].y2; seg[tot].r = (longdouble)tri[i].y - x + (longdouble)tri[i].x; } sort(seg + 1, seg + tot + 1); longdouble l = seg[1].l, len = .0; for (int i = 1; i <= tot; i++) { l = max(l, seg[i].l); if (seg[i].r - l > EPS) len += seg[i].r - l; l = max(l, seg[i].r); } return mp[x] = len; }
longdoubleintegral(longdouble l, longdouble r, longdouble eps, longdouble i){ longdouble mid = (l + r) / 2; longdouble iL = simpson(l, mid), iR = simpson(mid, r); if (fabs(iR + iL - i) <= eps) return iL + iR + fabs(iR + iL - i); return integral(l, mid, eps, iL) + integral(mid, r, eps, iR); }
voidinit(){ for (int i = 1; i <= n; i++) { if (vis[i]) continue; if (tri[i].x2 - tri[i].x == 0) { vis[i] = 1; continue; } for (int j = i + 1; j <= n; j++) { if (vis[j]) continue; if (tri[j].x2 - tri[j].x == 0) { vis[j] = 1; continue; } if (tri[j].y <= tri[i].y && tri[j].x >= tri[i].x && tri[j].x2 <= tri[i].x2 && tri[j].y2 >= tri[i].y2 && tri[j].y <= tri[i].y - (tri[j].x - tri[i].x)) { vis[j] = 1; } } } }
voidcalc(){ sort(pos.begin(), pos.end()); sort(tri + 1, tri + n + 1); auto edIt = unique(pos.begin(), pos.end()); init(); longdouble ans = .0; for (auto it = pos.begin() + 1; it != edIt; it++) { int l = *(it - 1), r = *it; chosen.clear(); for (int i = 1; i <= n; i++) { if (vis[i]) continue; if (tri[i].x >= r) break; if ((tri[i].x <= l && l <= tri[i].x2) || (tri[i].x <= r && r <= tri[i].x2)) chosen.emplace_back(i); } if (!chosen.size()) continue; longdouble L = 2 * EPS + l, R = - 2 * EPS + r; ans += integral(L, R, 1e-14, simpson(L, R)); } cout << setprecision(1) << fixed << ans; }
intmain(){ ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> x >> y >> m; tri[i].x = x, tri[i].y = y + m; tri[i].x2 = x + m, tri[i].y2 = y; pos.emplace_back(x), pos.emplace_back(x + m); } calc(); return0; }