This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub Luzhiled/comp-geometry
// verification-helper: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/CGL_7_I // verification-helper: ERROR 0.000001 #include "src/real-geometry/class/circle.hpp" #include "src/real-geometry/area/common-area-cc.hpp" #include "src/real-geometry/utility/io-set.hpp" #include <iostream> int main() { using R = long double; geometry::circle<R> c1, c2; std::cin >> c1.o >> c1.r; std::cin >> c2.o >> c2.r; std::cout << geometry::common_area_cc(c1, c2) << std::endl; }
#line 1 "test/aoj/cgl/7_I.test.cpp" // verification-helper: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/CGL_7_I // verification-helper: ERROR 0.000001 #line 2 "src/real-geometry/class/circle.hpp" #line 2 "src/real-geometry/class/point.hpp" #line 2 "src/real-geometry/class/vector.hpp" #include <complex> #include <iostream> 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" #include <vector> namespace geometry { template< typename R > using point = vec2d<R>; template< typename R > using points = std::vector< point< R > >; } #line 4 "src/real-geometry/class/circle.hpp" #line 6 "src/real-geometry/class/circle.hpp" // circle namespace geometry { template< typename R > class circle { public: point<R> o; R r; circle() = default; circle(point<R> o, R r) : o(o), r(r) {} const point<R> center() const { return o; } const R radius() const { return r; } }; template< typename R > using circles = std::vector< circle<R> >; } #line 2 "src/real-geometry/area/common-area-cc.hpp" #line 2 "src/real-geometry/common/const/pi.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/pi.hpp" #include <cmath> namespace geometry { static f80 pi() { static const f80 PI = acosl(-1); // no need `std::`. (?) return PI; } } #line 2 "src/real-geometry/utility/sign.hpp" #line 2 "src/real-geometry/common/const/eps.hpp" #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 7 "src/real-geometry/area/common-area-cc.hpp" #line 9 "src/real-geometry/area/common-area-cc.hpp" #include <algorithm> #line 11 "src/real-geometry/area/common-area-cc.hpp" namespace geometry { template< typename R > R common_area_cc(circle<R> a, circle<R> b) { using std::norm; if (a.r > b.r) std::swap(a, b); R d = std::abs(a.o - b.o); if (sign(a.r + b.r - d) <= 0) return 0; if (sign(d - (b.r - a.r)) <= 0) return norm(a.r) * pi(); R res = 0; for (int i = 0; i < 2; ++i) { R alpha = std::acos((norm(b.r) + norm(d) - norm(a.r)) / (2 * b.r * d)); R s = alpha * norm(b.r); R t = norm(b.r) * std::sin(alpha) * std::cos(alpha); res += s - t; std::swap(a, b); } return res; } } #line 2 "src/real-geometry/utility/io-set.hpp" #include <iomanip> namespace geometry { class IoSetup { using u32 = unsigned int; void set(std::ostream &os, u32 precision) { os << std::fixed << std::setprecision(precision); } public: IoSetup(u32 precision = 15) { std::cin.tie(0); std::ios::sync_with_stdio(0); set(std::cout, precision); set(std::cerr, precision); } } iosetup; } #line 7 "test/aoj/cgl/7_I.test.cpp" #line 9 "test/aoj/cgl/7_I.test.cpp" int main() { using R = long double; geometry::circle<R> c1, c2; std::cin >> c1.o >> c1.r; std::cin >> c2.o >> c2.r; std::cout << geometry::common_area_cc(c1, c2) << std::endl; }