HDU 2036 改革春风吹满地(数学)

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

struct poly
{
	int x,y;
}polygon[101];

double polygonarea(int N)
{
    int i,j;
    double area = 0;

    for (i=0;i<N;i++)
	 {
         j = (i + 1) % N;
         area += polygon[i].x * polygon[j].y;
         area -= polygon[i].y * polygon[j].x;
     }
 
    area /= 2.0;
    return(area < 0 ? -area : area);
}

int main() 
{
	int k,i,m,n,m1,n1,j,flag,N;
    while(~scanf("%d",&N),N)
    {
        for(i=0;i<N;i++)
        {
        	scanf("%d%d",&polygon[i].x,&polygon[i].y);
		}
		double res = polygonarea(N);
		printf("%.1lf\n",res);
	} 
	return 0;
}

你可能感兴趣的:(HDU 2036 改革春风吹满地(数学))