Give you a simple polygon, the border is plumb or aclinic. your task is calculate the area of the polygon.
输入格式
first line is n(n≤100)。following N lines contains X,Y, the vertexs show as counter-clockwise. -200≤x,y≤200。
输出格式
print the total area.
样例输入
10 0 0 4 0 4 1 3 1 3 3 2 3 2 2 1 2 1 3 0 3
样例输出
9
#include<stdio.h>
#include<math.h>
int main(){
int n,i,j;
double sum;
while(scanf("%d",&n)!=EOF){
sum=0.0;
double a[n][2];
for(i=0;i<n;i++)
for(j=0;j<2;j++)
scanf("%lf",&a[i][j]);
for(i=0;i<n-1;i++)
sum+=(a[i][0]*a[i+1][1]-a[i+1][0]*a[i][1])/2.0;
sum+=(a[n-1][0]*a[0][1]-a[0][0]*a[n-1][1])/2.0;
sum=fabs(sum);
printf("%d\n",(int)sum);
}
return 0;
}