Cod sursa(job #2445126)

Utilizator DavidLDavid Lauran DavidL Data 2 august 2019 16:32:00
Problema Aria Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <bits/stdc++.h>
#define x first
#define y second
#define ld long double
using namespace std;
ifstream fi("aria.in");
ofstream fo("aria.out");

int n;
pair <long double, long double> P[100005];
long double sx, sy;

long double dist(pair <ld, ld> A, pair <ld, ld> B)
{
    return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
}

long double arie(pair <ld, ld> A, pair <ld, ld> B, pair <ld, ld> C)
{
    ld AB = dist(A, B), AC = dist(A, C), BC = dist(B, C);
    ld p = (AB + AC + BC) / 2.00;

    return sqrt(p * (p - AB) * (p - AC) * (p - BC));
}

int main()
{
    fi >> n;
    for (int i = 1; i <= n; i++)
    {
        fi >> P[i].x >> P[i].y;
        sx += P[i].x;
        sy += P[i].y;
    }

    long double rez = 0;
    for (int i = 1; i < n; i++)
    {
        rez += arie(P[i], P[i + 1], {1.00 * sx / n, 1.00 * sy / n});
    }
    rez += arie(P[n], P[1], {1.00 * sx / n, 1.00 * sy / n});

    fo << fixed << setprecision(5) << rez;

    return 0;
}