1132: [POI2008]Tro
Description
平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和 N<=3000
Input
第一行给出数字N,N在[3,3000] 下面N行给出N个点的坐标,其值在[0,10000]
Output
保留一位小数,误差不超过0.1
Sample Input
5
0 0
1 2
0 2
1 0
1 1
0 0
1 2
0 2
1 0
1 1
Sample Output
7.0
http://hzwer.com/4668.html
1 #include<iostream> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<cstdio> 6 #include<algorithm> 7 #include<string> 8 #include<map> 9 #include<queue> 10 #include<vector> 11 #include<set> 12 #define inf 1000000000 13 #define maxn 3000+5 14 #define maxm 10000+5 15 #define eps 1e-10 16 #define ll long long 17 #define for0(i,n) for(int i=0;i<=(n);i++) 18 #define for1(i,n) for(int i=1;i<=(n);i++) 19 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 20 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 21 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) 22 using namespace std; 23 ll read(){ 24 ll x=0,f=1;char ch=getchar(); 25 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 26 while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} 27 return x*f; 28 } 29 int n,sumx,sumy; 30 ll ans; 31 struct P{ 32 int x,y; 33 }p[maxn],t[maxn]; 34 ll operator*(P a,P b){ 35 return a.x*b.y-a.y*b.x; 36 } 37 bool operator<(P a,P b){ 38 return a.y<b.y||(a.y==b.y&&a.x<b.x); 39 } 40 bool cmp(P a,P b){ 41 return a*b>0; 42 } 43 void solve(){ 44 sort(p+1,p+n+1); 45 for1(i,n-2){ 46 int top=0;sumx=sumy=0; 47 for(int j=i+1;j<=n;j++){ 48 top++; 49 t[top].x=p[j].x-p[i].x; 50 t[top].y=p[j].y-p[i].y; 51 } 52 sort(t+1,t+top+1,cmp); 53 for1(j,top){ 54 sumx+=t[j].x; 55 sumy+=t[j].y; 56 } 57 for1(j,top){ 58 sumx-=t[j].x; 59 sumy-=t[j].y; 60 ans+=(ll)t[j].x*sumy-(ll)t[j].y*sumx; 61 } 62 } 63 } 64 int main(){ 65 //freopen("input.txt","r",stdin); 66 //freopen("output.txt","w",stdout); 67 n=read(); 68 for1(i,n) 69 p[i].x=read(),p[i].y=read(); 70 solve(); 71 if(ans&1)printf("%lld.5",ans/2); 72 else printf("%lld.0",ans/2); 73 return 0; 74 return 0; 75 }