Cod sursa(job #2873878)

Utilizator AlexNeaguAlexandru AlexNeagu Data 19 martie 2022 11:57:46
Problema Aria Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.11 kb
#include <bits/stdc++.h>
using namespace std;
#define int long long
ifstream in("aria.in");
ofstream out("aria.out");
struct point {
	double x, y;
	void read() {
		in >> x >> y;
	}
	void write() {
		out << x << ' ' << y << '\n';
	}
	point operator - (const point &B) const {
		return point{x - B.x, y - B.y};
	}
	void operator -= (const point &B) {
		x -= B.x;
		y -= B.y;
	}
	double operator * (const point &B) const {
		return x * B.y - y * B.x;
	}
	double orientation(const point &A, const point &B) const {
		return (A - *this) * (B - *this);
	}
	double dist(point A) {
		A -= *this;
		return A.x * A.x + A.y * A.y;
	}
	bool operator <(const point &A) {
		if(x == A.x) {
			return y < A.y;
		}
		return x < A.x;
	}
		
};

 
int32_t main() {

    int N;
    in >> N;
    vector<point> polygon(N);
	for(int i = 0; i < N; ++i) {
        polygon[i].read();
    }
    double area = 0;
    for(int i = 2; i < N; ++i) {
        area += (polygon[i - 1] - polygon[0]) * (polygon[i] - polygon[0]);
    }
    area = abs(area);
    out << fixed << setprecision(6) << area / 2.0 << '\n';
}