Cod sursa(job #2565052)

Utilizator stefanpiturStefan Alexandru Pitur stefanpitur Data 2 martie 2020 11:50:29
Problema Aria Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

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

const int N = 100000;

struct punct{
    long double x, y;
};

punct poly[N+1];

long double getAreaTriangle(punct P1, punct P2, punct P3){
    long double area = (P1.x * (P2.y - P3.y) - P2.x * (P1.y - P3.y) + P3.x * (P1.y - P2.y)) / 2;
    return area;
}

long double getAreaPoli(punct coords[], int points, punct center){
    long double area = 0;
    for(int i=1; i<=points; i++)
        area += getAreaTriangle(coords[i-1], coords[i], center);
    return area;
}

int main()
{
    int n,i;
    fin >> n;
    for(i=0; i<n; i++)
        fin >> poly[i].x >> poly[i].y;
    poly[n] = poly[0];
    fout << setprecision(5) << fixed;
    fout << getAreaPoli(poly, n, poly[0]);
    return 0;
}