Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define x first
- #define y second
- const int maxn = 1e6+6;
- pair<int,int> punkty[2*maxn];
- bool cmp(pair<int,int> a, pair<int,int> b){
- return a.y<b.y;
- }
- int iloczyn(int x0, int y0, int x1, int y1, int x2, int y2){
- return ((x1-x0)*(y2-y0)-(x2-x0)*(y1-y0));
- }
- vector<int> stos;
- int main()
- {
- int n;
- cin >> n;
- for (int i=1; i<=n; i++)
- cin >> punkty[i].x >> punkty[i].y;
- sort(punkty+1, punkty+1+n, cmp);
- int nr = 1;
- for (int i=2*n-1; i>n; i--){
- punkty[i].x=punkty[nr].x;
- punkty[i].y=punkty[nr].y;
- nr++;
- }
- stos.push_back(1);
- stos.push_back(2);
- int ost = 1;
- for (int i=3; i<=2*n-1; i++)
- {
- int kon = stos[ost], przed = stos[ost-1];
- int ilo = iloczyn(punkty[przed].x, punkty[przed].y, punkty[kon].x, punkty[kon].y, punkty[i].x, punkty[i].y);
- while(ilo>0 && ost > 1)
- {
- stos.pop_back();
- ost--;
- kon = stos[ost], przed = stos[ost-1];
- ilo = iloczyn(punkty[przed].x, punkty[przed].y, punkty[kon].x, punkty[kon].y, punkty[i].x, punkty[i].y);
- }
- if (ilo>0)
- {
- stos.pop_back();
- ost--;
- }
- stos.push_back(i);
- ost++;
- }
- stos.pop_back();
- cout << "STOS:\n";
- for (int i=0; i<stos.size(); i++)
- cout << punkty[stos[i]].x << " " << punkty[stos[i]].y << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement