Cod sursa(job #2991234)

Utilizator tibinyteCozma Tiberiu-Stefan tibinyte Data 9 martie 2023 10:57:06
Problema Aria Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.16 kb
#include <bits/stdc++.h>

using namespace std;

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

const vector<int> dx = {-1, 0, 1, 0};
const vector<int> dy = {0, 1, 0, -1};

bool up(pair<int, int> p)
{
    return p.second > 0 or (p.second == 0 and p.first >= 0);
}

int cross(int x1, int y1, int x2, int y2)
{
    return x1 * y2 - y1 * x2;
}

double area(double x1, double y1, double x2, double y2, double x3, double y3)
{
    return abs((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<int, int>> points(n);
    for (int i = 0; i < n; ++i)
    {
        fin >> points[i].first >> points[i].second;
    }
    sort(points.begin(), points.end(), [&](pair<int, int> a, pair<int, int> b)
         { return up(a) == up(b) ? cross(a.first, a.second, b.first, b.second) > 0 : up(a) < up(b); });
    double ans = 0;
    for (int i = 1; i < n - 1; ++i)
    {
        ans += area(points[0].first, points[0].second, points[i].first, points[i].second, points[i + 1].first, points[i + 1].second);
    }
    fout << ans;
}