Cod sursa(job #2128718)

Utilizator FrequeAlex Iordachescu Freque Data 11 februarie 2018 23:00:57
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

ifstream fin("aria.in");
ofstream fout("aria.out");

const int NMAX = 100000 + 5;

struct point
{
    double x;
    double y;

    point()
    {
        x = 0;
        y = 0;
    }

    point(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
};

point v[NMAX];
int n;
double area;

double get_area()
{
    double sum = 0;
    for (int i = 1; i <= n; ++i)
        sum += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y;
    return sum / 2.0;
}

void write()
{
    fout << setprecision(5) << fixed << area;
}

void read()
{
    double x, y;

    fin >> n;
    for (int i = 1; i <= n; ++i)
    {
        fin >> x >> y;
        v[i] = point(x, y);
    }
    v[n + 1] = v[1];
}

int main()
{
    read();
    area = get_area();
    write();

    return 0;
}