Advertisement
Guest User

trojkaty

a guest
Jan 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define x first
  5. #define y second
  6. const int maxn = 2*1e6+6;
  7. pair<int,int> punkty[maxn];
  8.  
  9. bool cmp(pair<int,int> a, pair<int,int> b){
  10.     return a.y<b.y;
  11. }
  12. int iloczyn(int x0, int y0, int x1, int y1, int x2, int y2){
  13.     return ((x1-x0)*(y2-y0)-(x2-x0)*(y1-y0));
  14. }
  15. vector<int> stos;
  16.  
  17. main()
  18. {
  19.     ios_base::sync_with_stdio(0);
  20.     cin.tie(0);
  21.     int n;
  22.     cin >> n;
  23.     for (int i=1; i<=n; i++)
  24.         cin >> punkty[i].x >> punkty[i].y;
  25.     sort(punkty+1, punkty+1+n, cmp);
  26.     int nr = 1;
  27.     for (int i=2*n-1; i>n; i--){
  28.         punkty[i].x=punkty[nr].x;
  29.         punkty[i].y=punkty[nr].y;
  30.         nr++;
  31.     }
  32.     stos.push_back(1);
  33.     stos.push_back(2);
  34.     int ost = 1;
  35.     for (int i=3; i<=2*n-1; i++)
  36.     {
  37.         int kon = stos[ost], przed = stos[ost-1];
  38.         int ilo = iloczyn(punkty[przed].x, punkty[przed].y, punkty[kon].x, punkty[kon].y, punkty[i].x, punkty[i].y);
  39.         while(ilo>0 && ost>1) {
  40.             stos.pop_back();
  41.             ost--;
  42.             kon = stos[ost], przed = stos[ost-1];
  43.             ilo = iloczyn(punkty[przed].x, punkty[przed].y, punkty[kon].x, punkty[kon].y, punkty[i].x, punkty[i].y);
  44.         }
  45.         if (ilo>0) {
  46.             stos.pop_back();
  47.             ost--;
  48.         }
  49.         stos.push_back(i);
  50.         ost++;
  51.     }
  52.     stos.pop_back();
  53.     long long pole=0;
  54.     for (int i=1; i<stos.size()-1; i++)
  55.         pole+=iloczyn(punkty[stos[0]].x, punkty[stos[0]].y, punkty[stos[i]].x, punkty[stos[i]].y, punkty[stos[i+1]].x, punkty[stos[i+1]].y);
  56.     pole=abs(pole);
  57.     if (pole%2==0)
  58.         cout << pole/2 << ".000000";
  59.     else
  60.         cout << pole/2 << ".500000";
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement