Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <memory.h>
- #include <stdio.h>
- #include <stack>
- #include <deque>
- #include <queue>
- #include <set>
- #include <iterator>
- #include <map>
- #include <iomanip>
- #include <unordered_set>
- #include <array>
- //#define int long long
- #define pb push_back
- #define fir first
- #define sec second
- #define double long double
- #define endl "\n"
- #define un unsigned
- //#define INF 1000000000009
- //#define EPS 0.000000000001
- #define pii pair<int, int>
- #define all(v) v.begin(), v.end()
- using namespace std;
- class Point
- {
- public:
- long long x, y;
- Point(long long x, long long y) : x(x), y(y) {}
- Point() : x(0), y(0) {}
- };
- class Vector
- {
- public:
- Point a;
- Vector(long long x, long long y) : a({ x, y }) {}
- Vector(Point a, Point b) : a({ a.x - b.x, a.y - b.y }) {}
- };
- class Polygon
- {
- public:
- vector<Point> a;
- };
- Point vec(Point a, Point b)
- {
- return Point(b.x - a.x, b.y - a.y);
- }
- long long crossp(Point a, Point b)
- {
- return a.x * b.y - b.x * a.y;
- }
- long long dotp(Point a, Point b)
- {
- return a.x * b.x + a.y * b.y;
- }
- Point mn;
- bool cmp(Point a, Point b)
- {
- Vector v1(mn, a);
- Vector v2(mn, b);
- long long dt1 = crossp(v1.a, v2.a);
- if (dt1 != 0)
- {
- return dt1 > 0;
- }
- else
- {
- return dotp(v1.a, v1.a) < dotp(v2.a, v2.a);
- }
- }
- int orientation(Point a, Point b, Point c)
- {
- Vector v1(a, b);
- Vector v2(b, c);
- long long check = crossp(v1.a, v2.a);
- if (check == 0)
- {
- return 0;
- }
- else if (check < 0)
- {
- return -1;
- }
- else
- {
- return 1;
- }
- }
- Polygon convex_hull(Polygon& p)
- {
- if (p.a.size() == 1)
- {
- return p;
- }
- int min_pos = 0;
- for (int i = 1; i < (int)p.a.size(); i++)
- {
- if (p.a[min_pos].y > p.a[i].y)
- {
- min_pos = i;
- }
- else if (p.a[min_pos].y == p.a[i].y && p.a[min_pos].x > p.a[i].x)
- {
- min_pos = i;
- }
- }
- swap(p.a[min_pos], p.a[0]);
- mn = p.a[0];
- sort(all(p.a), cmp);
- Polygon hull;
- hull.a.push_back(mn);
- for (int i = 1; i < (int)p.a.size(); i++)
- {
- Point p0 = p.a[i];
- while ((int)hull.a.size() >= 2 && orientation(hull.a[hull.a.size() - 2], hull.a.back(), p0) <= 0)
- {
- hull.a.pop_back();
- }
- if (hull.a.back().x != p0.x || hull.a.back().y != p0.y)
- {
- hull.a.push_back(p0);
- }
- }
- return hull;
- }
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- n = 4;
- Polygon p;
- p.a.resize(n);
- for (int i = 0; i < n; i++)
- {
- cin >> p.a[i].x >> p.a[i].y;
- }
- p = convex_hull(p);
- if ((int)p.a.size() == 4)
- {
- cout << 1;
- }
- else
- {
- cout << 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement