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/courses/library/4/CGL/all/CGL_1_C #include "src/real-geometry/common/float-alias.hpp" #include "src/real-geometry/class/point.hpp" #include "src/real-geometry/operation/ccw.hpp" #include <iostream> using namespace geometry::number::ccw; int main() { using R = geometry::f80; using point = geometry::point< R >; point p0, p1; std::cin >> p0 >> p1; int q; std::cin >> q; while (q--) { point p2; std::cin >> p2; switch (geometry::ccw(p0, p1, p2)) { case COUNTER_CLOCKWISE: std::cout << "COUNTER_CLOCKWISE" << std::endl; break; case CLOCKWISE: std::cout << "CLOCKWISE" << std::endl; break; case ONLINE_BACK: std::cout << "ONLINE_BACK" << std::endl; break; case ONLINE_FRONT: std::cout << "ONLINE_FRONT" << std::endl; break; case ON_SEGMENT: std::cout << "ON_SEGMENT" << std::endl; break; } } }
#line 1 "test/aoj/cgl/1_C.test.cpp" // verification-helper: PROBLEM https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_1_C #line 2 "src/real-geometry/common/float-alias.hpp" namespace geometry { using f80 = long double; using f64 = double; } #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 2 "src/real-geometry/operation/ccw.hpp" #line 2 "src/real-geometry/numbers/ccw.hpp" namespace geometry::number::ccw { constexpr int COUNTER_CLOCKWISE = +1; constexpr int CLOCKWISE = -1; constexpr int ONLINE_BACK = +2; // c-a-b constexpr int ONLINE_FRONT = -2; // a-b-c constexpr int ON_SEGMENT = 0; // a-c-b } #line 2 "src/real-geometry/operation/cross-product.hpp" #line 4 "src/real-geometry/operation/cross-product.hpp" namespace geometry { template< typename R > R cross_product(const vec2d<R> &a, const vec2d<R> &b) { return a.x() * b.y() - a.y() * b.x(); } } #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 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 8 "src/real-geometry/operation/ccw.hpp" namespace geometry { using namespace geometry::number::ccw; template< typename R > int ccw(const point<R> &a, point<R> b, point<R> c) { b = b - a, c = c - a; if (sign(cross_product(b, c)) == +1) return COUNTER_CLOCKWISE; if (sign(cross_product(b, c)) == -1) return CLOCKWISE; if (sign(inner_product(b, c)) == -1) return ONLINE_BACK; if (std::norm(b) < std::norm(c)) return ONLINE_FRONT; return ON_SEGMENT; } } #line 6 "test/aoj/cgl/1_C.test.cpp" #line 8 "test/aoj/cgl/1_C.test.cpp" using namespace geometry::number::ccw; int main() { using R = geometry::f80; using point = geometry::point< R >; point p0, p1; std::cin >> p0 >> p1; int q; std::cin >> q; while (q--) { point p2; std::cin >> p2; switch (geometry::ccw(p0, p1, p2)) { case COUNTER_CLOCKWISE: std::cout << "COUNTER_CLOCKWISE" << std::endl; break; case CLOCKWISE: std::cout << "CLOCKWISE" << std::endl; break; case ONLINE_BACK: std::cout << "ONLINE_BACK" << std::endl; break; case ONLINE_FRONT: std::cout << "ONLINE_FRONT" << std::endl; break; case ON_SEGMENT: std::cout << "ON_SEGMENT" << std::endl; break; } } }