Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <string>
- #include <deque>
- #include <iomanip>
- #include <cstddef>
- #define F first
- #define S second
- using namespace std;
- struct point
- {
- double x, y;
- point():x(0.0), y(0.0){}
- point(double _x, double _y):x(_x), y(_y){}
- };
- point operator+(point a, point b)
- {
- return point(a.x + b.x, a.y + b.y);
- }
- point operator-(point a, point b)
- {
- return point(a.x - b.x, a.y - b.y);
- }
- point operator*(point a, double k)
- {
- return point(a.x * k, b.y * k);
- }
- point operator/(point a, double k)
- {
- return point(a.x / k, b.y / k);
- }
- double vect(point a, point b)
- {
- return a.x * b.y - a.y * b.x;
- }
- const long double eps = 0.000000005;
- const long double pi = 3.1415926535897932;
- const long long inf = 1e9;
- vector <point> all, up, down;
- bool comp(const point& a, const point& b)
- {
- return (a.x < b.x) || (a.x == b.x && a.y < b.y);
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
- // freopen("slalom.in", "r", stdin);freopen("slalom.out", "w", stdout);
- int n;
- cin >> n;
- double x, y;
- for (int i = 0; i < n; i++)
- {
- cin >> x >> y;
- all.push_back(point(x, y));
- }
- sort(all.begin(), all.end(), comp);
- point b = all[0], e = all.back();
- up.push_back(b);
- down.push_back(b);
- for (int i = 1; i < all.size(); i++)
- {
- point t = all[i];
- if (vect(e - b, t - b) > eps || i == all.size() - 1)
- {
- while (up.size() > 1 && vect(t - up.back(), up[up.size() - 2] - up.back()) > -eps)
- up.pop_back();
- up.push_back(t);
- }
- if (vect(e - b, t - b) < -eps || i == all.size() - 1)
- {
- while (down.size() > 1 && vect(t - down.back(), down[down.size() - 1] - down.back()) < eps)
- down.pop_back();
- down.push_back(t);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement