This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub Luzhiled/comp-geometry
// verification-helper: PROBLEM https://atcoder.jp/contests/abc181/tasks/abc181_f // verification-helper: ERROR 1e-4 #include <iostream> #include <vector> // union find {{{ class union_find { using data_type = int_fast32_t; std::vector< data_type > data_; public: union_find(std::size_t size) : data_(size, -1) {} std::size_t size() const { return data_.size(); } data_type get_root(data_type x) { return (data_[x] < 0 ? x : data_[x] = get_root(data_[x])); } bool is_root(data_type x) { return x == get_root(x); } bool is_same(data_type x, data_type y) { return get_root(x) == get_root(y); } void unite(data_type x, data_type y) { x = get_root(x); y = get_root(y); if (x == y) return; if (data_[x] > data_[y]) std::swap(x, y); data_[x] += data_[y]; data_[y] = x; } data_type element_count(data_type x) { return -data_[get_root(x)]; } }; // }}} #include "src/real-geometry/class/point.hpp" #include "src/real-geometry/distance/distance-lp.hpp" #include "src/real-geometry/utility/sign.hpp" int main() { using R = long double; using line = geometry::line<R>; using point = geometry::point<R>; using points = geometry::points<R>; using geometry::sign; line t(point(0, 100), point(1, 100)); line b(point(0, -100), point(1, -100)); int n; std::cin >> n; points pts(n); for (auto &p : pts) std::cin >> p; R ng = 200, ok = 0; for (int lb = 0; lb < 100; lb++) { R mid = (ok + ng) / 2; union_find uf(n + 2); int T = n, B = n + 1; for (int i = 0; i < n; i++) { point p = pts[i]; if (sign(geometry::distance_lp(t, p) - mid) < 0) uf.unite(T, i); if (sign(geometry::distance_lp(b, p) - mid) < 0) uf.unite(B, i); } for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { point p = pts[i], q = pts[j]; if (sign(std::abs(p - q) - mid) < 0) uf.unite(i, j); } } if (uf.is_same(T, B)) { ng = mid; } else { ok = mid; } } std::cout << ok / 2 << std::endl; }
#line 1 "test/atcoder/abc181_f.test.cpp" // verification-helper: PROBLEM https://atcoder.jp/contests/abc181/tasks/abc181_f // verification-helper: ERROR 1e-4 #include <iostream> #include <vector> // union find {{{ class union_find { using data_type = int_fast32_t; std::vector< data_type > data_; public: union_find(std::size_t size) : data_(size, -1) {} std::size_t size() const { return data_.size(); } data_type get_root(data_type x) { return (data_[x] < 0 ? x : data_[x] = get_root(data_[x])); } bool is_root(data_type x) { return x == get_root(x); } bool is_same(data_type x, data_type y) { return get_root(x) == get_root(y); } void unite(data_type x, data_type y) { x = get_root(x); y = get_root(y); if (x == y) return; if (data_[x] > data_[y]) std::swap(x, y); data_[x] += data_[y]; data_[y] = x; } data_type element_count(data_type x) { return -data_[get_root(x)]; } }; // }}} #line 2 "src/real-geometry/class/point.hpp" #line 2 "src/real-geometry/class/vector.hpp" #include <complex> #line 5 "src/real-geometry/class/vector.hpp" namespace geometry { template< typename R > class vec2d : public std::complex< R > { using complex = std::complex< R >; public: using complex::complex; vec2d(const complex &c): complex::complex(c) {} const R x() const { return this->real(); } const R y() const { return this->imag(); } friend vec2d operator*(const vec2d &v, const R &k) { return vec2d(v.x() * k, v.y() * k); } friend vec2d operator*(const R &k, const vec2d &v) { return vec2d(v.x() * k, v.y() * k); } friend std::istream &operator>>(std::istream &is, vec2d &v) { R x, y; is >> x >> y; v = vec2d(x, y); return is; } }; } #line 4 "src/real-geometry/class/point.hpp" #line 6 "src/real-geometry/class/point.hpp" namespace geometry { template< typename R > using point = vec2d<R>; template< typename R > using points = std::vector< point< R > >; } #line 2 "src/real-geometry/distance/distance-lp.hpp" #line 2 "src/real-geometry/class/line.hpp" #line 2 "src/real-geometry/utility/equals/vector.hpp" #line 2 "src/real-geometry/utility/equals/real-number.hpp" #line 2 "src/real-geometry/utility/sign.hpp" #line 2 "src/real-geometry/common/const/eps.hpp" #line 2 "src/real-geometry/common/float-alias.hpp" namespace geometry { using f80 = long double; using f64 = double; } #line 4 "src/real-geometry/common/const/eps.hpp" namespace geometry { inline static f80 &eps() { static f80 EPS = 1e-10; return EPS; } void set_eps(f80 EPS) { eps() = EPS; } } #line 2 "src/real-geometry/numbers/sign.hpp" #line 2 "src/real-geometry/common/int-alias.hpp" namespace geometry { using i32 = int; using i64 = long long; } #line 4 "src/real-geometry/numbers/sign.hpp" namespace geometry::number::sign { constexpr i32 PLUS = +1; constexpr i32 ZERO = 0; constexpr i32 MINUS = -1; } #line 5 "src/real-geometry/utility/sign.hpp" namespace geometry { using namespace geometry::number::sign; template< typename R > inline int sign(R r) { if (r < -eps()) return MINUS; if (r > +eps()) return PLUS; return ZERO; } } #line 4 "src/real-geometry/utility/equals/real-number.hpp" namespace geometry { template< typename R > bool equals(R a, R b) { return sign(a - b) == 0; } } #line 5 "src/real-geometry/utility/equals/vector.hpp" namespace geometry { template< typename R > bool equals(const vec2d<R> &a, const vec2d<R> &b) { return equals(a.x(), b.x()) and equals(a.y(), b.y()); } } #line 5 "src/real-geometry/class/line.hpp" #include <cassert> #line 8 "src/real-geometry/class/line.hpp" namespace geometry { template< typename R > class line { using P = point<R>; public: P a, b; line() = default; line(P a, P b) : a(a), b(b) { assert(not equals(a, b)); } }; template< typename R > using lines = std::vector< line<R> >; } #line 2 "src/real-geometry/mapping/projection.hpp" #line 2 "src/real-geometry/operation/inner-product.hpp" #line 4 "src/real-geometry/operation/inner-product.hpp" namespace geometry { template< typename R > R inner_product(const vec2d<R> &a, const vec2d<R> &b) { return a.x() * b.x() + a.y() * b.y(); } } #line 6 "src/real-geometry/mapping/projection.hpp" #line 8 "src/real-geometry/mapping/projection.hpp" namespace geometry { template< typename R > point<R> projection(const line<R> &l, const point<R> &p) { R t = inner_product<R>(p - l.a, l.a - l.b) / std::norm(l.a - l.b); return l.a + (l.a - l.b) * t; } } #line 6 "src/real-geometry/distance/distance-lp.hpp" namespace geometry { template< typename R > R distance_lp(const line<R> &l, const point<R> &p) { point<R> pr = projection(l, p); return std::abs(pr - p); } } #line 50 "test/atcoder/abc181_f.test.cpp" int main() { using R = long double; using line = geometry::line<R>; using point = geometry::point<R>; using points = geometry::points<R>; using geometry::sign; line t(point(0, 100), point(1, 100)); line b(point(0, -100), point(1, -100)); int n; std::cin >> n; points pts(n); for (auto &p : pts) std::cin >> p; R ng = 200, ok = 0; for (int lb = 0; lb < 100; lb++) { R mid = (ok + ng) / 2; union_find uf(n + 2); int T = n, B = n + 1; for (int i = 0; i < n; i++) { point p = pts[i]; if (sign(geometry::distance_lp(t, p) - mid) < 0) uf.unite(T, i); if (sign(geometry::distance_lp(b, p) - mid) < 0) uf.unite(B, i); } for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { point p = pts[i], q = pts[j]; if (sign(std::abs(p - q) - mid) < 0) uf.unite(i, j); } } if (uf.is_same(T, B)) { ng = mid; } else { ok = mid; } } std::cout << ok / 2 << std::endl; }