Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Make CSP great again
- //You're as beautiful as the day I lost you
- #include <bits/stdc++.h>
- #define TASK "CONVEXHULL"
- #define Log2(x) 31 - __builtin_clz(x)
- using namespace std;
- const int N = 1e5;
- int n;
- struct TPoint
- {
- long long x, y;
- };
- using TVector = TPoint;
- TVector operator - (const TVector & a, const TVector & b)
- {
- return {b.x - a.x, b.y - a.y};
- }
- long long operator * (const TVector & a, const TVector & b)
- {
- return a.x * b.y - a.y * b.x;
- }
- long long distance(TPoint a, TPoint b)
- {
- return (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);
- }
- TPoint p[N + 1];
- TVector convex[N + 1];
- void read()
- {
- cin >> n;
- for (int i = 0; i < n; ++ i)
- {
- cin >> p[i].x >> p[i].y;
- }
- swap(*min_element(p, p + n, [](const TPoint & a, const TPoint & b)
- {
- if (a.y != b.y)
- {
- return a.y < b.y;
- }
- else
- {
- return a.x < b.x;
- }
- }), p[0]);
- sort(p + 1, p + n, [](const TPoint & a, const TPoint & b)
- {
- long long tmp = (a - p[0]) * (b - p[0]);
- if (tmp != 0)
- {
- return tmp > 0;
- }
- return distance(a, p[0]) < distance(p[0], b);
- });
- }
- bool TurnLeft(TVector & a, TVector & b, TVector & c)
- {
- return (b - a) * (c - b) > 0;
- }
- void solve()
- {
- int m = 0;
- for (int i = 0; i < n; ++ i)
- {
- while(m >= 2 && !TurnLeft(convex[m - 1], convex[m], p[i]))
- {
- --m;
- }
- ++m;
- convex[m] = p[i];
- }
- cout << m << '\n';
- long long s = 0;
- TVector O = {0, 0};
- convex[m + 1] = convex[1];
- for (int i = 1; i <= m; ++ i)
- {
- s += convex[i] * convex[i + 1];
- }
- cout << fixed << setprecision(1) << (long double)s/ 2 << '\n';
- for (int i = 1; i <= m; ++ i)
- {
- cout << convex[i].x << ' ' << convex[i].y << '\n';
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- if (fopen(TASK".INP", "r"))
- {
- freopen(TASK".INP", "r", stdin);
- freopen(TASK".OUT", "w", stdout);
- }
- int t = 1;
- bool typetest = false;
- if (typetest)
- {
- cin >> t;
- }
- for (int __ = 1; __ <= t; ++ __)
- {
- //cout << "Case " << __ << ": ";
- read();
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement