Cod sursa(job #1834386)

Utilizator bostanmateiBostan Matei-Calin bostanmatei Data 24 decembrie 2016 15:07:34
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <cmath>
#include <iomanip>

using namespace std;
ifstream fin("aria.in");
ofstream fout("aria.out");
long double area_tot;
int n;
struct point
{
    int x, y;
};
point p[100005];
double areat(point a, point b, point c)
{
    a.x -= c.x; b.x -= c.x;
    a.y -= c.y; b.y -= c.y;
    return fabs((long double)(a.x * b.y - b.x * a.y) / 2);
    //return fabs((int)(a.x * b.y - b.x * a.y) / 2);
}

double area(int n, point p[])
{
    long double area_tot = 0;
    for (int i = 2; i < n; i++)
        area_tot += areat(p[1], p[i], p[i + 1]);
    return area_tot;
}
int main()
{
    fin >> n;
    for(int i = 1; i <= n; i++)
        fin >> p[i].x >> p[i].y;
    area_tot = area(n, p);
    //fout << fixed << setprecision(5) << abs(area_tot) << '\n';
    fout << fabs(area_tot) << '\n';
    return 0;
}