bzoj1132 [POI2008]Tro

题目链接

对点排序,按顺序往后找,找之前极角排序,保证面积为正

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<string>
 7 #include<cmath>
 8 #include<ctime>
 9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<set>
13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
15 #define Clear(a,b) memset(a,b,sizeof(a))
16 #define inout(x) printf("%d",(x))
17 #define douin(x) scanf("%lf",&x)
18 #define strin(x) scanf("%s",(x))
19 #define LLin(x) scanf("%lld",&x)
20 #define op operator
21 #define CSC main
22 typedef unsigned long long ULL;
23 typedef const int cint;
24 typedef long long LL;
25 using namespace std;
26 void inin(int &ret)
27 {
28     ret=0;int f=0;char ch=getchar();
29     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
30     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
31     ret=f?-ret:ret;
32 }
33 struct xl
34 {
35     LL x,y;
36     xl(LL x=0,LL y=0):x(x),y(y){}
37     void in(){LLin(x),LLin(y);}
38     bool op < (const xl &a)const {return x==a.x?y<a.y:x<a.x;}
39     xl op + (const xl &a)const {return xl(x+a.x,y+a.y);}
40     xl op - (const xl &a)const {return xl(x-a.x,y-a.y);}
41     xl op * (const LL &a)const {return xl(x*a,y*a);}
42     xl op / (const LL &a)const {return xl(x/a,y/a);}
43 };
44 LL D_(const xl &a,const xl &b){return a.x*b.x+a.y*b.y;}
45 LL X_(const xl &a,const xl &b){return a.x*b.y-a.y*b.x;}
46 bool com(const xl &a,const xl &b)
47 {
48     return X_(a,b)>0;
49 }
50 xl p[3030];
51 xl sta[3030];int top;
52 int n;
53 int main()
54 {
55     inin(n);
56     re(i,1,n)p[i].in();
57     LL ans=0;
58     sort(p+1,p+n+1);
59     re(i,1,n-2)
60     {
61         top=0;xl temp=xl(0,0);
62         re(j,i+1,n)sta[++top]=p[j]-p[i];
63         sort(sta+1,sta+top+1,com);
64         re(j,1,top)
65         {
66             ans+=X_(temp,sta[j]);
67             temp=temp+sta[j];
68         }
69     }
70     printf("%lld.%d",ans>>1,ans&1?5:0);
71      return 0;
72 }

 

posted @ 2016-03-15 20:19  HugeGun  阅读(134)  评论(0编辑  收藏  举报