Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define int long long
- #define x first
- #define y second
- const int maxn = 2*1e6+6;
- pair<int,int> punkty[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;
- main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- 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();
- long long pole=0;
- for (int i=1; i<stos.size()-1; i++)
- 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);
- pole=abs(pole);
- if (pole%2==0)
- cout << pole/2 << ".000000";
- else
- cout << pole/2 << ".500000";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement