首页 > 代码库 > hdoj:2036

hdoj:2036

#include <iostream>
using namespace std;
struct Point
{
    int x, y;

};
Point a[101];
int main()
{
    int n;
    while (cin >> n && n != 0)
    {
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i].x >> a[i].y;
        }

        double area = 0.0;
        for (int i = 1; i < n; i++)
        {
            int x1 = a[i].x;
            int y1 = a[i].y;
            int x2 = a[i + 1].x;
            int y2 = a[i + 1].y;
            area += 0.5*abs(x1*y2 - y1*x2);
        }
        int x1 = a[1].x;
        int y1 = a[1].y;
        int x2 = a[n].x;
        int y2 = a[n].y;
        area += 0.5*abs(x1*y2 - y1*x2);
        printf("%.1lf\n", area);
    }
}

 

hdoj:2036