This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub ebi-fly13/icpc_library
#define PROBLEM \ "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1623&lang=jp" #include "../../geometry/base_arbitary.hpp" #include "../../template/template.hpp" #include "../../utility/rational.hpp" using namespace lib; using vec = Vec<rational>; using line = Line<rational>; const vector<vector<int>> order = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; int main() { while (true) { vector<vec> ia(3), b(3); rep(i, 0, 6) { ll x, y; cin >> x >> y; if (!cin) return 0; (i < 3 ? ia[i] : b[i - 3]) = vec(x, y); } int ans = 5; for (auto fid : order) for (auto tid : order) rep(j, 0, 2) { auto a = ia; int cur = 0; rep(i, 0, 3) { int f = fid[i], t = tid[i]; if (a[f] == b[t]) continue; cur++; int p = (f + 1) % 3, q = (f + 2) % 3; if (cross(a[p] - a[q], b[t] - a[f]) == 0) { a[f] = b[t]; continue; } cur++; if (j == 1) swap(p, q); line l1({a[p], a[p] + a[f] - b[t]}), l2({a[q], a[q] + a[f] - a[p]}); if (intersection(l1, l2) == 1) { a[q] = cross_point(l1, l2); a[f] = b[t]; } else { cur = 5; break; } } chmin(ans, cur); } if (ans == 5) cout << "Many" << endl; else cout << ans << endl; } }
#line 1 "test/geometry/base_rational.test.cpp" #define PROBLEM \ "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1623&lang=jp" #line 2 "geometry/base_arbitary.hpp" #line 2 "template/template.hpp" #include <bits/stdc++.h> #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) #define all(v) v.begin(), v.end() using ll = long long; using ld = long double; using ull = unsigned long long; template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } namespace lib { using namespace std; } // namespace lib // using namespace lib; #line 4 "geometry/base_arbitary.hpp" namespace lib { template <typename T> struct Vec { T x, y; Vec(T _x = T(0), T _y = T(0)) : x(_x), y(_y) {} Vec& operator*=(const T& a) { x *= a; y *= a; return *this; } Vec& operator/=(const T& a) { x /= a; y /= a; return *this; } Vec& operator+=(const Vec& rhs) { x += rhs.x; y += rhs.y; return *this; } Vec& operator-=(const Vec& rhs) { x -= rhs.x; y -= rhs.y; return *this; } friend bool operator==(const Vec& lhs, const Vec& rhs) { return lhs.x == rhs.x && lhs.y == rhs.y; } friend bool operator!=(const Vec& lhs, const Vec& rhs) { return lhs.x != rhs.x || lhs.y != rhs.y; } friend Vec operator+(const Vec& lhs, const Vec& rhs) { return Vec(lhs) += rhs; } friend Vec operator-(const Vec& lhs, const Vec& rhs) { return Vec(lhs) -= rhs; } friend Vec operator*(const Vec& lhs, const T& rhs) { return Vec(lhs) *= rhs; } friend Vec operator*(const T& rhs, const Vec& lhs) { return Vec(lhs) *= rhs; } friend Vec operator/(const Vec& lhs, const T& rhs) { return Vec(lhs) /= rhs; } friend Vec operator/(const T& rhs, const Vec& lhs) { return Vec(lhs) /= rhs; } }; template <typename T> T dot(const Vec<T>& a, const Vec<T>& b) { return a.x * b.x + a.y * b.y; } // cross > 0 : counter clockwise a -> b template <typename T> T cross(const Vec<T>& a, const Vec<T>& b) { return a.x * b.y - a.y * b.x; } template <typename T> ld abs(const Vec<T>& a) { return sqrtl(a.x * a.x + a.y * a.y); } template <typename T> T norm(const Vec<T>& a) { return a.x * a.x + a.y * a.y; } template <typename T> struct Line { Vec<T> p, q; }; template <typename T> int intersection(const Line<T>& a, const Line<T>& b) { if (cross(a.p - a.q, b.p - b.q) == 0) { if (cross(a.p - b.p, a.q - b.p) == 0) return 2; return 0; } return 1; } // intersection == 1 (cross(a.p-a.q,b.p-b.q) != 0) template <typename T> Vec<T> cross_point(const Line<T>& a, const Line<T>& b) { Vec<T> va = a.p - a.q, vb = b.p - b.q; Vec<T> ba = b.p - a.q; T alpha = cross(ba, vb) / cross(va, vb); return alpha * a.p + (1 - alpha) * a.q; } } // namespace lib #line 2 "utility/rational.hpp" #line 4 "utility/rational.hpp" namespace lib { struct rational { rational() : p(0), q(1) {} rational(ll n) : p(n), q(1) {} rational(ll n, ll m) { assert(m != 0); if (m < 0) n = -n, m = -m; ll g = gcd(n, m); p = n / g; q = m / g; } explicit operator const ld () const { return ld(p) / ld(q); } rational& operator+=(const rational& rhs){ ll g = gcd(q, rhs.q); ll np = rhs.q / g * p + q / g * rhs.p; ll nq = q / g * rhs.q; ll ng = gcd(np, nq); p = np / ng, q = nq / ng; return *this; } rational& operator-=(const rational& rhs) { (*this) += rational(-rhs.p, rhs.q); return *this; } rational& operator*=(const rational& rhs) { ll g1 = gcd(q, rhs.p), g2 = gcd(p, rhs.q); ll np = p / g2 * rhs.p / g1; ll nq = q / g1 * rhs.q / g2; p = np, q = nq; return *this; } rational& operator/=(const rational& rhs) { (*this) *= rational(rhs.q, rhs.p); return *this; } rational operator+() const { return *this; } rational operator-() const { return rational() - *this; } friend rational operator+(const rational& lhs, const rational& rhs) { return rational(lhs) += rhs; } friend rational operator-(const rational& lhs, const rational& rhs) { return rational(lhs) -= rhs; } friend rational operator*(const rational& lhs, const rational& rhs) { return rational(lhs) *= rhs; } friend rational operator/(const rational& lhs, const rational& rhs) { return rational(lhs) /= rhs; } friend bool operator==(const rational& lhs, const rational& rhs) { return lhs.p == rhs.p && lhs.q == rhs.q; } friend bool operator!=(const rational& lhs, const rational& rhs) { return lhs.p != rhs.p || lhs.q != rhs.q; } friend bool operator<(const rational lhs, const rational rhs) { return less_than(lhs, rhs); } friend bool operator>(const rational lhs, const rational rhs) { return less_than(rhs, lhs); } friend bool operator<=(const rational lhs, const rational rhs) { return lhs == rhs || lhs < rhs; } friend bool operator>=(const rational lhs, const rational rhs) { return lhs == rhs || lhs > rhs; } friend std::ostream& operator<<(std::ostream& os, const rational& r) { return os << r.p << " / " << r.q; } std::pair<ll,ll> val() const { return {p, q}; } private: ll p, q; static bool less_than(rational lhs, rational rhs) { __int128_t lv = __int128_t(lhs.p) * __int128_t(rhs.q); __int128_t rv = __int128_t(lhs.q) * __int128_t(rhs.p); return lv < rv; } }; } // namespace lib #line 7 "test/geometry/base_rational.test.cpp" using namespace lib; using vec = Vec<rational>; using line = Line<rational>; const vector<vector<int>> order = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; int main() { while (true) { vector<vec> ia(3), b(3); rep(i, 0, 6) { ll x, y; cin >> x >> y; if (!cin) return 0; (i < 3 ? ia[i] : b[i - 3]) = vec(x, y); } int ans = 5; for (auto fid : order) for (auto tid : order) rep(j, 0, 2) { auto a = ia; int cur = 0; rep(i, 0, 3) { int f = fid[i], t = tid[i]; if (a[f] == b[t]) continue; cur++; int p = (f + 1) % 3, q = (f + 2) % 3; if (cross(a[p] - a[q], b[t] - a[f]) == 0) { a[f] = b[t]; continue; } cur++; if (j == 1) swap(p, q); line l1({a[p], a[p] + a[f] - b[t]}), l2({a[q], a[q] + a[f] - a[p]}); if (intersection(l1, l2) == 1) { a[q] = cross_point(l1, l2); a[f] = b[t]; } else { cur = 5; break; } } chmin(ans, cur); } if (ans == 5) cout << "Many" << endl; else cout << ans << endl; } }