Cod sursa(job #2154745)

Utilizator CammieCamelia Lazar Cammie Data 7 martie 2018 11:39:19
Problema Aria Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include <fstream>
#include <iomanip>

using namespace std;

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

struct punct{
    long double x, y;
};

inline long double det(punct c1, punct c2, punct c3) {
    long double delta = c1.x * c2.y + c2.x * c3.y + c1.y * c3.x - c2.y * c3.x - c1.x * c3.y - c2.x * c1.y;
    if (delta < 0) delta *= -1;

    long double sol = delta / (long double) 2;

    return sol;
}

inline void Read() {
    int N;
    punct start, ante, curent;

    fin >> N; long double s = 0;

    fin >> start.x >> start.y;
    fin >> ante.x >> ante.y;

    for (int i = 3; i <= N; i++) {
        fin >> curent.x >> curent.y;

        s += det(start, ante, curent);

        ante = curent;
    }

    fout << fixed << setprecision(5) << s;
}

int main () {
    Read();

    fin.close(); fout.close(); return 0;
}