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 83 84 85 86 87 88 89 90 91 92 93
| #include<bits/stdc++.h> #define INIT(a,b) memset(a,b,sizeof(a)) #define LL long long using namespace std; const int inf=0x3f3f3f3f; const int maxn=1e5+7; const int mod=1e9+7; struct Node{ double x,y,k; bool operator < (const Node & e){return k<e.k;} Node operator - (Node p){return (Node){x-p.x,y-p.y,0};} double operator * (Node p){return x*p.y-y*p.x;} }node[maxn]; int n; double cha(int q1,int q2,int q3){ Node a=node[q2]-node[q1]; Node b=node[q3]-node[q2]; double res= a * b; if(res>1e-10) return res; else return 0; } double tubao(){ double minx=inf;int sit=0; for(int i=0;i<n;i++){ if(minx>node[i].x){ minx=node[i].x; sit=i; } }
swap(node[0],node[sit]); for(int i=1;i<n;i++){ if(node[i].x!=node[0].x) node[i].k=(node[i].y-node[0].y)/(node[i].x-node[0].x); else { if(node[i].y>node[0].y) node[i].k=inf; else node[i].k=-inf; } }
sort(node+1,node+n); int ans[maxn],top=-1; ans[++top]=0;ans[++top]=1; for(int i=2;i<n;i++){ if(cha(ans[top],i,(i+1)%n)) ans[++top]=i; else { while(!cha(ans[top-1],ans[top],(i+1)%n)){ top--; } if(i+1!=n){ ans[++top]=i+1; i++; } } } double s=0; for(int i=1;i<top;i++){ s+=0.5*cha(0,ans[i],ans[i+1]); } return s; } int main(){ int t; while(~scanf("%d",&t)){ while(t--){ scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf%lf",&node[i].x,&node[i].y); double s=tubao(); printf("%.1lf\n",s); } }
return 0; }
|