Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define all(x) begin(x), end(x)
- #define equal std_equal
- #define not_equal std_not_equal
- #define less std_less
- #define less_equal std_less_equal
- #define greater std_greater
- #define greater_equal std_greater_equal
- #define map std_map
- #define vector std_vector
- #include <bits/stdc++.h>
- #undef equal
- #undef not_equal
- #undef less
- #undef less_equal
- #undef greater
- #undef greater_equal
- #undef map
- #undef vector
- using namespace std;
- template<class A>
- void addlog(A a) {
- cerr << a << endl;
- }
- template<class A, class... B>
- void addlog(A a, B... b) {
- cerr << a << ' ';
- addlog(b...);
- }
- typedef long double float80_t;
- static_assert(sizeof(float80_t) >= 10, "it's not float80_t");
- const float80_t eps = { 1e-9 };
- inline bool equal(float80_t a, float80_t b) {
- return fabs(a - b) <= eps;
- }
- inline bool not_equal(float80_t a, float80_t b) {
- return fabs(a - b) > eps;
- }
- inline bool less(float80_t a, float80_t b) {
- return a < b - eps;
- }
- inline bool greater(float80_t a, float80_t b) {
- return a > b + eps;
- }
- inline bool less_equal(float80_t a, float80_t b) {
- return a <= b + eps;
- }
- inline bool greater_equal(float80_t a, float80_t b) {
- return a >= b - eps;
- }
- void accurate_output() {
- cout.precision(19);
- cerr.precision(19);
- cout << fixed;
- cerr << fixed;
- }
- float80_t to_radians(float80_t x)
- { return x * M_PI / 180; }
- float80_t to_degrees(float80_t x)
- { return x * 180 / M_PI; }
- int64_t to_int(float80_t x) {
- float80_t r = round(x + 0.5);
- assert(equal(r, x));
- return (int64_t)(r);
- }
- struct point {
- float80_t x, y;
- point() : x(0), y(0) {}
- point(float80_t x_, float80_t y_) : x(x_), y(y_) {}
- friend ostream &operator<<(ostream &out, point p)
- { return out << p.x << ' ' << p.y; }
- friend istream &operator>>(istream &in, point &p)
- { return in >> p.x >> p.y; }
- };
- struct vector : public point {
- vector() : point() {}
- vector(float80_t x_, float80_t y_) : point(x_, y_) {}
- vector(point a, point b) : point(b.x - a.x, b.y - a.y) {}
- float80_t len_square() const
- { return x * x + y + y; }
- float80_t len() const
- { return sqrt((float80_t)(len_square())); }
- float80_t ang() const
- { return atan2(y, x); }
- friend float80_t ang(vector a, vector b)
- { return atan2(cross_product(a, b), dot_product(a, b)); }
- vector operator-()
- { return vector(-x, -y); }
- vector operator*(float80_t c)
- { return vector(x * c, y * c); }
- vector operator/(float80_t c)
- { return vector(x / c, y / c); }
- friend point operator+(point a, vector b)
- { return point(a.x + b.x, a.y + b.y); }
- friend point operator-(point a, vector b)
- { return a + (-b); }
- friend point &operator+=(point &a, vector b)
- { return a = a + b; }
- friend point &operator-=(point &a, vector b)
- { return a = a - b; }
- friend float80_t dot_product(vector a, vector b)
- { return a.x * b.x + a.y * b.y; }
- friend float80_t cross_product(vector a, vector b)
- { return a.x * b.y - b.x * a.y; }
- friend vector operator+(vector a, vector b)
- { return vector(a.x + b.x, a.y + b.y); }
- friend vector operator-(vector a, vector b)
- { return a + (-b); }
- vector &operator+=(vector other)
- { return (*this) = (*this) + other; }
- vector &operator-=(vector other)
- { return (*this) = (*this) - other; }
- vector normalized(float80_t len_need=1)
- { return vector(x * len_need / len(), y * len_need / len()); }
- vector rotated(float80_t cosa, float80_t sina)
- { return vector(x * cosa - y * sina, x * sina + y * cosa); }
- vector rotated(float80_t angle)
- { return rotated(cos(angle), sin(angle)); }
- static vector from_polar(float80_t angle, float80_t len_need=1)
- { return vector(len_need * cos(angle), len_need * sin(angle)); }
- };
- typedef int32_t cross_t;
- const cross_t collapse = 1e9;
- bool equal(point a, point b) {
- return equal(a.x, b.x) && equal(a.y, b.y);
- }
- bool not_equal(point a, point b) {
- return not_equal(a.x, b.x) || not_equal(a.y, b.y);
- }
- bool on_line(point o, point a, point b) {
- assert(not_equal(a, b));
- return equal(cross_product(vector(o, a), vector(o, b)), 0);
- }
- bool on_ray(point o, point a, point b) {
- assert(not_equal(a, b));
- return on_line(o, a, b)
- && greater_equal(dot_product(vector(a, o), vector(a, b)), 0);
- }
- bool on_segment(point o, point a, point b) {
- if (equal(a, b)) {
- assert(false);
- return equal(a, o);
- } else {
- return on_line(o, a, b)
- && less(dot_product(vector(o, a), vector(o, b)), 0);
- }
- }
- float80_t signed_triangle_square(point a, point b, point c)
- { return cross_product(vector(a, b), vector(a, c)) / 2; }
- float80_t triangle_square(point a, point b, point c)
- { return fabs(signed_triangle_square(a, b, c)); }
- cross_t cross_lines(point a, point b, point c, point d) {
- assert(not_equal(a, b));
- assert(not_equal(c, d));
- float80_t s_acd = signed_triangle_square(a, c, d);
- float80_t s_bcd = -signed_triangle_square(b, c, d);
- if (equal(s_acd, -s_bcd)) {
- return equal(s_acd, 0) ? collapse : 0;
- } else {
- return 1;
- }
- }
- point line_intersection(point a, point b, point c, point d) {
- assert(cross_lines(a, b, c, d) == 1);
- float80_t s_acd = signed_triangle_square(a, c, d);
- float80_t s_bcd = -signed_triangle_square(b, c, d);
- return a + (vector(a, b) * s_acd / (s_acd + s_bcd));
- }
- void run();
- int main() {
- #ifdef LOCAL
- while (true)
- #endif
- run();
- return 0;
- }
- void run() {
- ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement