Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- using namespace std;
- typedef long long ll;
- struct point{
- ll x, y;
- point() {}
- point(ll a, ll b) {
- x = a;
- y = b;
- }
- point operator-(point &p) {
- return point(x - p.x, y - p.y);
- }
- ll operator^(const point &p) const {
- return x*p.y - y*p.x;
- }
- bool operator<(const point &p) const {
- return (x==p.x) ? (y < p.y) : (x < p.x);
- }
- bool operator==(const point &p) const {
- return x == p.x and y == p.y;
- }
- };
- vector<point> convex_hull(vector<point> v) {
- sort(v.begin(), v.end());
- vector<point> up;
- vector<point> lo;
- up.pb(v[0]);
- for(int i = 1; i < v.size(); i++) {
- while(up.size() > 1 and ((up.back() - up[up.size() - 2])^(v[i] - up.back())) > 0LL) {
- up.pop_back();
- }
- up.pb(v[i]);
- }
- lo.pb(v.back());
- for(int i = int(v.size()) - 2; i >= 0; i--) {
- while(lo.size() > 1 and ((lo.back() - lo[lo.size() - 2])^(v[i] - lo.back())) > 0LL) {
- lo.pop_back();
- }
- lo.pb(v[i]);
- }
- for(int i = 1; i < int(lo.size()) - 1; i++) {
- up.pb(lo[i]);
- }
- return up;
- }
- vector<point> p1, p2;
- vector<point> allp;
- int main(int argc, char* argv[]) {
- int n, m;
- cin >> n >> m;
- for(int i = 0; i < n; i++) {
- int x, y;
- cin >> x >> y;
- p1.pb(point(x, y));
- allp.pb(point(x, y));
- }
- for(int i = 0; i < m; i++) {
- int x, y;
- cin >> x >> y;
- p2.pb(point(x, y));
- allp.pb(point(x, y));
- }
- sort(p1.begin(), p1.end());
- sort(p2.begin(), p2.end());
- vector<point> ch = convex_hull(allp);
- sort(ch.begin(), ch.end());
- cout << ((ch == p1 or ch == p2) ? "YES" : "NO") << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement