WOJ1213-Area

来源:互联网 发布:程序员的工作环境 编辑:程序博客网 时间:2024/06/07 23:51

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.

样例输入

100 04 04 13 13 32 32 21 21 30 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;}


原创粉丝点击