Cod sursa(job #3202014)

Utilizator not_anduAndu Scheusan not_andu Data 10 februarie 2024 12:49:57
Problema Aria Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

#define INFILE "aria.in"
#define OUTFILE "aria.out"

struct Point {

    double x, y;

    Point() : x(0), y(0) {}
    Point(int _x, int _y) : x(_x), y(_y) {}

};

double produsPuncte(Point &a, Point &b){
    return (a.x * b.y - b.x * a.y);
}

void solve(){

    int n; cin >> n;
    vector<Point> v(n + 1);

    for(int i = 0; i < n; ++i){
        cin >> v[i].x >> v[i].y;
    }

    v[n].x = v[0].x, v[n].y = v[0].y;

    double ans = 0;

    for(int i = 0; i < n; ++i){
        ans += produsPuncte(v[i], v[i + 1]);
    }

    ans /= 2;

    if(ans < 0) ans = -ans;

    cout << fixed << setprecision(5) << ans << '\n';

}

int main(){
    ios_base::sync_with_stdio(false);
    freopen(INFILE, "r", stdin);
    freopen(OUTFILE, "w", stdout);
    cin.tie(0), cout.tie(0);
    solve();
    return 0;
}