解法就是用有向面积法,叉积就可以。最后如果是负数的话取个相反数就OK了,代码也很简单,如下。
1 Show Code - Run ID 1166912
2
3 Submit Time: 2012-02-18 01:33:04 Language: GNU C Result: Accepted
4 Pid: 3124 Time: 0.00 sec. Memory: 852 K. Code Length: 0.6 K.
5 # include <stdio.h>
6 # define cross(x1,y1,x2,y2) (x1)*(y2)-(x2)*(y1)
7 # define get_aera(x0,y0,x1,y1,x2,y2) (cross((x1)-(x0),(y1)-(y0),(x2)-(x0),(y2)-(y0)))
8 int main()
9 {
10 int n;
11 while(scanf("%d",&n)!=EOF&&n)
12 {
13 int i;
14
15 double x[3],y[3],aera=0;
16 scanf("%lf%lf",&x[2],&y[2]);
17 for(i=1;i<n;i++)
18 {
19 scanf("%lf%lf",&x[i%2],&y[i%2]);
20 if(i>1) aera+=get_aera(x[2],y[2],x[(i+1)%2],y[(i+1)%2],x[i%2],y[i%2]);
21 }
22 aera*=0.5;
23 if(aera<0) aera=-aera;
24 printf("%.0f\n",aera+1e-8);
25
26 }
27 return 0;
28 }