Cod sursa(job #1801723)

Utilizator FragentisMihai Petru Fragentis Data 9 noiembrie 2016 16:18:34
Problema Aria Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;

struct Point {long double x, y;};

inline long double det(Point p1, Point p2, Point p3)
{
    return p1.x*p2.y - p3.x*p2.y + p2.x*p3.y - p1.x*p3.y + p3.x*p1.y - p1.y*p2.x;
}

int main()
{
    fstream f("aria.in", ios::in);
    int n, i;
    long double s;
    Point p1, p2, p3;

    f >> n;
    f >> p1.x >> p1.y;
    f >> p2.x >> p2.y;

    s = 0;
    for(i = 2; i <= n-1; ++i)
    {
        f >> p3.x >> p3.y;
        s += det(p1,p2,p3) / 2.0;
        p2 = p3;
    }

    f.close();
    f.open("aria.out", ios::out);
    f << abs(s);

    return 0;
}