Cod sursa(job #2763211)

Utilizator tigaieNedelcu Ioan-Andrei tigaie Data 12 iulie 2021 14:29:51
Problema Aria Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.57 kb
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FOR(i , n) for(int i = 0 ; i < (n) ; i++)
#define apare printf("apare");
#define endl "\n"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int , int> pii;
////==================================================
const int inf = INT_MAX;

struct point{
    ///structura de punct
    long double x, y;
    bool operator < (const point& o){
        return x * o.y - y * o.x < 0;
    }
};

long double dot(point p, point q){
    ///produsul scalar
    return p.x * q.x + p.y * q.y;
}
long double cross(point p, point q){
    ///produsul vectorial
    return p.x * q.y - p.y * q.x;
}

long double cross(point p1, point p2, point p3) {
    ///produs vectorial 3 puncte
    return (p2.x - p1.x)*(p3.y - p1.y) - (p3.x - p1.x)*(p2.y - p1.y);
}

long double area(vector<point>& v){
    ///aria delimitata d o multime de puncte
    long double res = 0;
    int n = v.size();
    for(int i=0; i<n; i++)
        res += cross(v[i], v[(i+1)%n]);
    return res;
}

//vector<point> v;
//populare cu puncte dintr-un singur cadran
//sort(v.begin(), v.end());
vector<point> sequence;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    freopen("aria.in" , "r" , stdin);
    freopen("aria.out" , "w" , stdout);
    int n;
    cin >> n;
    long double a , b;
    FOR(i , n){
        cin >> a >> b;
        sequence.push_back({a , b});
    }
    cout << fixed << setprecision(8) << (long double)abs(0.5 * area(sequence));
    return 0x0;
}