Cod sursa(job #3005647)

Utilizator tibinyteCozma Tiberiu-Stefan tibinyte Data 17 martie 2023 09:58:24
Problema Aria Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

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

long double area(long double x1, long double y1, long double x2, long double y2, long double x3, long double y3)
{
    return ((y2 + y1) * (x1 - x2) + (y1 + y3) * (x3 - x1) - (y2 + y3) * (x3 - x2)) * 0.5;
}

int32_t main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    fin >> n;
    vector<pair<long double, long double>> a(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        fin >> a[i].first >> a[i].second;
    }
    a.push_back(a[1]);
    long double ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        ans += area(0, 0, a[i].first, a[i].second, a[i + 1].first, a[i + 1].second);
    }
    fout << fixed << setprecision(10) << abs(ans) << '\n';
}