Cod sursa(job #2105205)

Utilizator Steve_ITStefan Ursache Steve_IT Data 12 ianuarie 2018 20:03:59
Problema Aria Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>
#include <cmath>
#include <iomanip>

using namespace std;

ifstream f ("aria.in");
ofstream g ("aria.out");

struct point {
    float x, y;
};
double area (point a, point b, point c) {
    a.x-=c.x; b.x-=c.x;
    a.y-=c.y; b.y-=c.y;
    return fabs((double)(a.x*b.y-b.x*a.y)/2);
}
double area (int n, point p[]) {
    double area_tot = 0;
    for(int i=2; i<n; i++) {
        area_tot += area(p[1], p[i], p[i+1]);
    }
    return area_tot;
}

int n, i;
point p[100003];

int main()
{
    f>>n;
    for(i=1; i<=n; i++)
        f>>p[i].x>>p[i].y;
    g<<fixed<<setprecision(5)<<area(n, p);
    return 0;
}