Cod sursa(job #1786659)

Utilizator roxannemafteiuMafteiu-Scai Roxana roxannemafteiu Data 23 octombrie 2016 14:09:01
Problema Aria Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <cmath>
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;

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

struct Point {
    double x, y;
    Point(double x, double y) {
        this->x = x;
        this->y = y;
    };
};

int N;
double solution, x, y;
vector<Point> points;

void read() {
    fin >> N;
    for(int i = 0; i < N; ++i) {
        fin >> x >> y;
        points.emplace_back(Point(x, y));
    }
}

void solve() {
    points.emplace_back(points[0].x, points[0].y);
    for(int i = 0; i < N; ++i) {
        solution += (points[i].x * points[i + 1].y - points[i + 1].x * points[i].y);
    }

    fout << setprecision(5) << fabs(solution / 2);
}

int main() {
    read();
    solve();

    return 0;
}