1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <bits/stdc++.h> #define Orz ios::sync_with_stdio(0),cin.tie(0) #define rep(i,a,b) for(int i=a;i<=b;i++) #define pii pair<int,int> #define pdd pair<double,double> #define int long long #define ll long long #define ld long double #define N 100001 #define eps 1e-9 #define x first #define y second
using namespace std;
struct pt{ int x,y; bool operator < (pt b){ if(x == b.x)return y < b.y; return x < b.x; } bool operator > (pt b){ if(x == b.x)return y > b.y; return x > b.x; } bool operator == (pt b){ if(x-b.x<=eps && y-b.y<=eps)return true; return false; } pt operator+(pt b) {return {x + b.x, y + b.y};} pt operator-(pt b) {return {x - b.x, y - b.y};} int operator^(pt b) {return x * b.y - y * b.x;} int operator*(pt b) {return x * b.x + y * b.y;} }; bool cmp(pt a, pt b){ if(a.x == b.x)return a.y < b.y; return a.x < b.x; }
vector<pt> p;
bool check(pt a,pt b,pt o){ int cross = (a - o)^(b - o); return cross >= 0; }
int n,t;
vector<pt> convex_hull(){ vector<pt> hull; sort(p.begin(),p.end(),cmp); for(auto i : p){ while(hull.size() > 1 && check(i,hull[hull.size()-1],hull[hull.size()-2])){ hull.pop_back(); } hull.push_back(i); } int down_hull = hull.size(); hull.pop_back(); reverse(p.begin(),p.end()); for(auto i: p){ while(hull.size() > down_hull && check(i,hull[hull.size()-1],hull[hull.size()-2])){ hull.pop_back(); } hull.push_back(i); } return hull; }
signed main(){ Orz; cin>>t; while(t--){ cin>>n; p.assign(n,{0,0}); rep(i,0,n-1)cin>>p[i].x>>p[i].y; vector<pt> hull = convex_hull(); int area = 0,len = hull.size(); for(int i=0;i<len-1;i++)area += (hull[i]^hull[i+1]); cout<<fixed<<setprecision(1)<<((ld)area/2)<<endl; } }
|