Cod sursa(job #1795506)

Utilizator Chirita_MateiChirita Matei Chirita_Matei Data 2 noiembrie 2016 16:36:45
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream>
#include <iomanip>

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

struct point{
    long double x;
    long double y;
}v[4];

long double area(point a, point b, point c)
{
    a.x -= c.x;
    b.x -= c.x;

    a.y -= c.y;
    b.y -= c.y;

    long double d=(long double)(a.x * b.y - a.y * b.x)/(long double)2;

    /*if(d >= 0)
    {
        return d;
    }

    else
    {
        return 0 - d;
    }*/

    return d;
}

int main()
{
    int n, i;
    long double s = 0;

    fin >> n;

    for(i = 1; i <= n; i++)
    {
        if(i < 3)
        {
            fin >> v[i].x >> v[i].y;
        }

        if(i > 3)
        {
            v[2] = v[3];
            fin >> v[3].x >> v[3].y;
            s += area(v[1],v[2],v[3]);
        }

        if(i == 3)
        {
            fin >> v[3].x >> v[3].y;
            s += area(v[1],v[2],v[3]);
        }
    }

    if(s<0) s=-s;

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

    return 0;
}