Skip to content

Commit 89c31bb

Browse files
committed
reupload Geometry
1 parent 4800f97 commit 89c31bb

File tree

7 files changed

+652
-0
lines changed

7 files changed

+652
-0
lines changed

src/2189.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
#define print_op(...) ostream& operator<<(ostream& out, const __VA_ARGS__& u)
6+
template<typename A, typename B> print_op(pair<A, B>) { return out << "(" << u.first << ", " << u.second << ")"; }
7+
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> print_op(T_container) { out << "{"; string sep; for (const T &x : u) out << sep << x, sep = ", "; return out << "}"; }
8+
template<typename T> void dbg_out(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";}
9+
template<typename T, typename... Args> void dbg_out(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
10+
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; dbg_out(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
11+
#ifdef LOCAL
12+
#define dbg(...) dbg_out(#__VA_ARGS__, __VA_ARGS__)
13+
#else
14+
#define dbg(...)
15+
#endif
16+
17+
#define ar array
18+
#define ll long long
19+
#define ld long double
20+
#define sz(x) ((int)x.size())
21+
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
22+
#define all(a) (a).begin(), (a).end()
23+
24+
const int MAX_N = 1e5 + 5;
25+
const int MAX_L = 20;
26+
const int MAX_C = 26;
27+
const ll MOD = 1e9 + 7;
28+
const ll INF = 1e9;
29+
const ld EPS = 1e-9;
30+
31+
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
32+
template <class T> struct Point {
33+
T x, y;
34+
Point() : x(0), y(0) {}
35+
Point(const T& _x, const T& _y) : x(_x), y(_y) {}
36+
37+
friend std::ostream& operator<<(std::ostream& out, const Point& p) { return out << "(" << p.x << "," << p.y << ")"; }
38+
friend std::istream& operator>>(std::istream& in, Point& p) { return in >> p.x >> p.y; }
39+
40+
friend bool operator==(const Point& a, const Point& b) { return tie(a.x, a.y) == tie(b.x, b.y); }
41+
friend bool operator!=(const Point& a, const Point& b) { return tie(a.x, a.y) != tie(b.x, b.y); }
42+
friend bool operator<(const Point& a, const Point& b) { return tie(a.x, a.y) < tie(b.x, b.y); }
43+
44+
Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
45+
Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
46+
Point operator*(const T& d) const { return Point(x * d, y * d); }
47+
Point operator/(const T& d) const { return Point(x / d, y / d); }
48+
49+
T dot(const Point& p) const { return x * p.x + y * p.y; }
50+
T cross(const Point& p) const { return x * p.y - y * p.x; }
51+
T cross(const Point& a, const Point& b) const { return (a - *this).cross(b - *this); }
52+
T dist2() const { return x * x + y * y; }
53+
double dist() const { return sqrt((double)dist2()); }
54+
double angle() const { return atan2(y, x); } // [-pi, pi] to x-axis
55+
56+
Point unit() const { return *this / dist(); } // unit vector
57+
Point perp() const { return P(-y, x); } // rotates +90 degrees
58+
Point normal() const { return perp().unit(); }
59+
Point rotate(const double& a) const { return P(x*cos(a) - y*sin(a), x*sin(a) + y*cos(a)); } // ccw around (0,0)
60+
};
61+
62+
using pt = Point<ll>;
63+
64+
void solve(int tc = 0) {
65+
pt p1, p2, p3; cin >> p1 >> p2 >> p3;
66+
ll x = p1.cross(p3, p2);
67+
if (x == 0) {
68+
cout << "TOUCH\n";
69+
} else if (x < 0) {
70+
cout << "LEFT\n";
71+
} else {
72+
cout << "RIGHT\n";
73+
}
74+
}
75+
76+
signed main() {
77+
ios_base::sync_with_stdio(false); cin.tie(NULL);
78+
int tc = 1;
79+
cin >> tc;
80+
for (int t = 1; t <= tc; t++) {
81+
// cout << "Case #" << t << ": ";
82+
solve(t);
83+
}
84+
}

src/2190.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
#define print_op(...) ostream& operator<<(ostream& out, const __VA_ARGS__& u)
6+
template<typename A, typename B> print_op(pair<A, B>) { return out << "(" << u.first << ", " << u.second << ")"; }
7+
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> print_op(T_container) { out << "{"; string sep; for (const T &x : u) out << sep << x, sep = ", "; return out << "}"; }
8+
template<typename T> void dbg_out(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";}
9+
template<typename T, typename... Args> void dbg_out(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
10+
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; dbg_out(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
11+
#ifdef LOCAL
12+
#define dbg(...) dbg_out(#__VA_ARGS__, __VA_ARGS__)
13+
#else
14+
#define dbg(...)
15+
#endif
16+
17+
#define ar array
18+
#define ll long long
19+
#define ld long double
20+
#define sz(x) ((int)x.size())
21+
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
22+
#define all(a) (a).begin(), (a).end()
23+
24+
const int MAX_N = 1e5 + 5;
25+
const int MAX_L = 20;
26+
const int MAX_C = 26;
27+
const ll MOD = 1e9 + 7;
28+
const ll INF = 1e9;
29+
const ld EPS = 1e-9;
30+
31+
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
32+
template <class T> struct Point {
33+
T x, y;
34+
Point() : x(0), y(0) {}
35+
Point(const T& _x, const T& _y) : x(_x), y(_y) {}
36+
37+
friend std::ostream& operator<<(std::ostream& out, const Point& p) { return out << "(" << p.x << "," << p.y << ")"; }
38+
friend std::istream& operator>>(std::istream& in, Point& p) { return in >> p.x >> p.y; }
39+
40+
friend bool operator==(const Point& a, const Point& b) { return tie(a.x, a.y) == tie(b.x, b.y); }
41+
friend bool operator!=(const Point& a, const Point& b) { return tie(a.x, a.y) != tie(b.x, b.y); }
42+
friend bool operator<(const Point& a, const Point& b) { return tie(a.x, a.y) < tie(b.x, b.y); }
43+
44+
Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
45+
Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
46+
Point operator*(const T& d) const { return Point(x * d, y * d); }
47+
Point operator/(const T& d) const { return Point(x / d, y / d); }
48+
49+
T dot(const Point& p) const { return x * p.x + y * p.y; }
50+
T cross(const Point& p) const { return x * p.y - y * p.x; }
51+
T cross(const Point& a, const Point& b) const { return (a - *this).cross(b - *this); }
52+
T dist2() const { return x * x + y * y; }
53+
double dist() const { return sqrt((double)dist2()); }
54+
double angle() const { return atan2(y, x); } // [-pi, pi] to x-axis
55+
56+
Point unit() const { return *this / dist(); } // unit vector
57+
Point perp() const { return P(-y, x); } // rotates +90 degrees
58+
Point normal() const { return perp().unit(); }
59+
Point rotate(const double& a) const { return P(x*cos(a) - y*sin(a), x*sin(a) + y*cos(a)); } // ccw around (0,0)
60+
};
61+
62+
using pt = Point<ll>;
63+
64+
template<class P> bool onSegment(P s, P e, P p) {
65+
return p.cross(s, e) == 0 && (s - p).dot(e - p) <= 0;
66+
}
67+
68+
template<class P> vector<P> segInter(P a, P b, P c, P d) {
69+
auto oa = c.cross(d, a), ob = c.cross(d, b),
70+
oc = a.cross(b, c), od = a.cross(b, d);
71+
// Checks if intersection is single non-endpoint point.
72+
if (sgn(oa) * sgn(ob) < 0 && sgn(oc) * sgn(od) < 0)
73+
return {(a * ob - b * oa) / (ob - oa)};
74+
set<P> s;
75+
if (onSegment(c, d, a)) s.insert(a);
76+
if (onSegment(c, d, b)) s.insert(b);
77+
if (onSegment(a, b, c)) s.insert(c);
78+
if (onSegment(a, b, d)) s.insert(d);
79+
return {all(s)};
80+
}
81+
82+
void solve(int tc = 0) {
83+
pt p1, p2, p3, p4; cin >> p1 >> p2 >> p3 >> p4;
84+
cout << (segInter(p1, p2, p3, p4).empty() ? "NO" : "YES") << "\n";
85+
}
86+
87+
signed main() {
88+
ios_base::sync_with_stdio(false); cin.tie(NULL);
89+
int tc = 1;
90+
cin >> tc;
91+
for (int t = 1; t <= tc; t++) {
92+
// cout << "Case #" << t << ": ";
93+
solve(t);
94+
}
95+
}

src/2191.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
#define print_op(...) ostream& operator<<(ostream& out, const __VA_ARGS__& u)
6+
template<typename A, typename B> print_op(pair<A, B>) { return out << "(" << u.first << ", " << u.second << ")"; }
7+
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> print_op(T_container) { out << "{"; string sep; for (const T &x : u) out << sep << x, sep = ", "; return out << "}"; }
8+
template<typename T> void dbg_out(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";}
9+
template<typename T, typename... Args> void dbg_out(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
10+
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; dbg_out(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
11+
#ifdef LOCAL
12+
#define dbg(...) dbg_out(#__VA_ARGS__, __VA_ARGS__)
13+
#else
14+
#define dbg(...)
15+
#endif
16+
17+
#define ar array
18+
#define ll long long
19+
#define ld long double
20+
#define sz(x) ((int)x.size())
21+
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
22+
#define all(a) (a).begin(), (a).end()
23+
24+
const int MAX_N = 1e5 + 5;
25+
const int MAX_L = 20;
26+
const int MAX_C = 26;
27+
const ll MOD = 1e9 + 7;
28+
const ll INF = 1e9;
29+
const ld EPS = 1e-9;
30+
31+
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
32+
template <class T> struct Point {
33+
T x, y;
34+
Point() : x(0), y(0) {}
35+
Point(const T& _x, const T& _y) : x(_x), y(_y) {}
36+
37+
friend std::ostream& operator<<(std::ostream& out, const Point& p) { return out << "(" << p.x << "," << p.y << ")"; }
38+
friend std::istream& operator>>(std::istream& in, Point& p) { return in >> p.x >> p.y; }
39+
40+
friend bool operator==(const Point& a, const Point& b) { return tie(a.x, a.y) == tie(b.x, b.y); }
41+
friend bool operator!=(const Point& a, const Point& b) { return tie(a.x, a.y) != tie(b.x, b.y); }
42+
friend bool operator<(const Point& a, const Point& b) { return tie(a.x, a.y) < tie(b.x, b.y); }
43+
44+
Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
45+
Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
46+
Point operator*(const T& d) const { return Point(x * d, y * d); }
47+
Point operator/(const T& d) const { return Point(x / d, y / d); }
48+
49+
T dot(const Point& p) const { return x * p.x + y * p.y; }
50+
T cross(const Point& p) const { return x * p.y - y * p.x; }
51+
T cross(const Point& a, const Point& b) const { return (a - *this).cross(b - *this); }
52+
T dist2() const { return x * x + y * y; }
53+
double dist() const { return sqrt((double)dist2()); }
54+
double angle() const { return atan2(y, x); } // [-pi, pi] to x-axis
55+
56+
Point unit() const { return *this / dist(); } // unit vector
57+
Point perp() const { return P(-y, x); } // rotates +90 degrees
58+
Point normal() const { return perp().unit(); }
59+
Point rotate(const double& a) const { return P(x*cos(a) - y*sin(a), x*sin(a) + y*cos(a)); } // ccw around (0,0)
60+
};
61+
62+
using pt = Point<ll>;
63+
64+
template<class T>
65+
T polygonArea2(vector<Point<T>>& v) {
66+
T a = v.back().cross(v[0]);
67+
rep(i,0,sz(v)-1) a += v[i].cross(v[i+1]);
68+
return a;
69+
}
70+
71+
void solve(int tc = 0) {
72+
int n; cin >> n;
73+
vector<pt> a(n);
74+
for (pt &p : a) cin >> p;
75+
cout << abs(polygonArea2(a)) << "\n";
76+
}
77+
78+
signed main() {
79+
ios_base::sync_with_stdio(false); cin.tie(NULL);
80+
int tc = 1;
81+
// cin >> tc;
82+
for (int t = 1; t <= tc; t++) {
83+
// cout << "Case #" << t << ": ";
84+
solve(t);
85+
}
86+
}

src/2192.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
#define print_op(...) ostream& operator<<(ostream& out, const __VA_ARGS__& u)
6+
template<typename A, typename B> print_op(pair<A, B>) { return out << "(" << u.first << ", " << u.second << ")"; }
7+
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> print_op(T_container) { out << "{"; string sep; for (const T &x : u) out << sep << x, sep = ", "; return out << "}"; }
8+
template<typename T> void dbg_out(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";}
9+
template<typename T, typename... Args> void dbg_out(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
10+
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; dbg_out(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
11+
#ifdef LOCAL
12+
#define dbg(...) dbg_out(#__VA_ARGS__, __VA_ARGS__)
13+
#else
14+
#define dbg(...)
15+
#endif
16+
17+
#define ar array
18+
#define ll long long
19+
#define ld long double
20+
#define sz(x) ((int)x.size())
21+
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
22+
#define all(a) (a).begin(), (a).end()
23+
24+
const int MAX_N = 1e5 + 5;
25+
const int MAX_L = 20;
26+
const int MAX_C = 26;
27+
const ll MOD = 1e9 + 7;
28+
const ll INF = 1e9;
29+
const ld EPS = 1e-9;
30+
31+
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
32+
template <class T> struct Point {
33+
T x, y;
34+
Point() : x(0), y(0) {}
35+
Point(const T& _x, const T& _y) : x(_x), y(_y) {}
36+
37+
friend std::ostream& operator<<(std::ostream& out, const Point& p) { return out << "(" << p.x << "," << p.y << ")"; }
38+
friend std::istream& operator>>(std::istream& in, Point& p) { return in >> p.x >> p.y; }
39+
40+
friend bool operator==(const Point& a, const Point& b) { return tie(a.x, a.y) == tie(b.x, b.y); }
41+
friend bool operator!=(const Point& a, const Point& b) { return tie(a.x, a.y) != tie(b.x, b.y); }
42+
friend bool operator<(const Point& a, const Point& b) { return tie(a.x, a.y) < tie(b.x, b.y); }
43+
44+
Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
45+
Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
46+
Point operator*(const T& d) const { return Point(x * d, y * d); }
47+
Point operator/(const T& d) const { return Point(x / d, y / d); }
48+
49+
T dot(const Point& p) const { return x * p.x + y * p.y; }
50+
T cross(const Point& p) const { return x * p.y - y * p.x; }
51+
T cross(const Point& a, const Point& b) const { return (a - *this).cross(b - *this); }
52+
T dist2() const { return x * x + y * y; }
53+
double dist() const { return sqrt((double)dist2()); }
54+
double angle() const { return atan2(y, x); } // [-pi, pi] to x-axis
55+
56+
Point unit() const { return *this / dist(); } // unit vector
57+
Point perp() const { return P(-y, x); } // rotates +90 degrees
58+
Point normal() const { return perp().unit(); }
59+
Point rotate(const double& a) const { return P(x*cos(a) - y*sin(a), x*sin(a) + y*cos(a)); } // ccw around (0,0)
60+
};
61+
62+
using pt = Point<ll>;
63+
64+
template<class P> bool onSegment(P s, P e, P p) {
65+
return p.cross(s, e) == 0 && (s - p).dot(e - p) <= 0;
66+
}
67+
68+
template<class P>
69+
int inPolygon(vector<P> &p, P a) {
70+
int cnt = 0, n = sz(p);
71+
rep(i,0,n) {
72+
P q = p[(i + 1) % n];
73+
if (onSegment(p[i], q, a)) return 2;
74+
cnt ^= ((a.y<p[i].y) - (a.y<q.y)) * a.cross(p[i], q) > 0;
75+
}
76+
return !!cnt;
77+
}
78+
79+
void solve(int tc = 0) {
80+
int n, q; cin >> n >> q;
81+
vector<pt> a(n);
82+
for (pt &p : a) cin >> p;
83+
while (q--) {
84+
pt p; cin >> p;
85+
int ans = inPolygon(a, p);
86+
if (ans == 0) {
87+
cout << "OUTSIDE\n";
88+
} else if (ans == 1) {
89+
cout << "INSIDE\n";
90+
} else {
91+
cout << "BOUNDARY\n";
92+
}
93+
}
94+
}
95+
96+
signed main() {
97+
ios_base::sync_with_stdio(false); cin.tie(NULL);
98+
int tc = 1;
99+
// cin >> tc;
100+
for (int t = 1; t <= tc; t++) {
101+
// cout << "Case #" << t << ": ";
102+
solve(t);
103+
}
104+
}

0 commit comments

Comments
 (0)