Cod sursa(job #2156733)

Utilizator DawlauAndrei Blahovici Dawlau Data 8 martie 2018 22:59:16
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include<fstream>
#include<iomanip>
using namespace std;
ifstream fin("aria.in");
ofstream fout("aria.out");
typedef long double ld;

struct Point{

    ld x, y;
};

inline ld determinant(Point firstPoint, Point secondPoint){

    return firstPoint.x * secondPoint.y - secondPoint.x * firstPoint.y;
}

int main(){

    int pointsCnt;
    ld area = 0;
    Point firstPoint, secondPoint, auxFirstPoint;

    fin >> pointsCnt >> firstPoint.x >> firstPoint.y;
    auxFirstPoint = firstPoint;

    int idx;
    for(idx = 2; idx <= pointsCnt; ++idx){

        fin >> secondPoint.x >> secondPoint.y;
        area += determinant(firstPoint, secondPoint);
        firstPoint = secondPoint;
    }
    fin >> secondPoint.x >> secondPoint.y;
    area += determinant(firstPoint, auxFirstPoint);

    fout << fixed << setprecision(6) << area / 2;
}