Cod sursa(job #2749091)

Utilizator richardbaczur1Baczur Richard richardbaczur1 Data 4 mai 2021 22:30:10
Problema Aria Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>
#include <vector>
#include <cmath>
#include <iomanip>
#define infile "aria.in"
#define outfile "aria.out"

struct point {
    double x, y;

    point(double x, double y) : x(x), y(y) {}
};

std::ifstream f(infile);
std::ofstream g(outfile);

std::vector<point> v;
int n, i;

int main()
{
    f >> n;

    for (i = 0; i < n; ++i)
    {
        double x, y;
        f >> x >> y;
        v.emplace_back(x, y);
    }

    double sol = 0;

    v.emplace_back(v[0].x, v[0].y);
    for (i = 0; i < n; ++i)
    {
        sol += (v[i].x * v[i + 1].y - v[i + 1].x * v[i].y);
    }

    g << std::fixed << std::setprecision(5) << fabs(sol / 2.0);
    return 0;
}