标签:
每次都选最左边的点,然后以这个点为原点
统计和这个点构成的三角形面积和
不难想到极角排序然后由叉积很容易求出
1 const oo=1 shl 30; 2 eps=1e-8; 3 var i,j,k,m,n:longint; 4 x,y:array[0..6010] of longint; 5 z:array[0..6010] of double; 6 ans,xx,yy:int64; 7 8 procedure swap(var a,b:longint); 9 var c:longint; 10 begin 11 c:=a; 12 a:=b; 13 b:=c; 14 end; 15 16 procedure sort(l,r:longint); 17 var i,j:longint; 18 p,q:double; 19 begin 20 i:=l; j:=r; 21 p:=z[(l+r) shr 1]; 22 repeat 23 while z[i]<p-eps do inc(i); 24 while z[j]>p+eps do dec(j); 25 if i<=j then 26 begin 27 swap(x[i],x[j]); 28 swap(y[i],y[j]); 29 q:=z[i]; z[i]:=z[j]; z[j]:=q; 30 inc(i); dec(j); 31 end; 32 until i>j; 33 if l<j then sort(l,j); 34 if i<r then sort(i,r); 35 end; 36 37 begin 38 readln(n); 39 for i:=1 to n do 40 readln(x[i],y[i]); 41 for i:=1 to n-2 do 42 begin 43 k:=i; 44 for j:=i to n do 45 if x[j]<x[k] then k:=j; 46 swap(x[i],x[k]); 47 swap(y[i],y[k]); 48 for j:=i+1 to n do 49 if x[j]=x[i] then 50 if y[j]>y[i] then z[j]:=oo 51 else z[j]:=-oo 52 else z[j]:=(y[j]-y[i])/(x[j]-x[i]); 53 sort(i+1,n); 54 xx:=0; yy:=0; 55 for j:=i+1 to n do 56 begin 57 ans:=ans+(x[j]-x[i])*yy-(y[j]-y[i])*xx; 58 xx:=xx+x[j]-x[i]; yy:=yy+y[j]-y[i]; 59 end; 60 end; 61 writeln(abs(ans)/2:0:1); 62 end.
标签:
原文地址:http://www.cnblogs.com/phile/p/4533360.html