Cod sursa(job #3218766)

Utilizator MagicantPlusIuoras Andrei MagicantPlus Data 28 martie 2024 08:33:39
Problema Aria Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.72 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>

using namespace std;

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

const long double margin = 0.00000001;

struct Point
{
    long double x, y;

    void operator=(Point t);
};
struct Polygon
{
    vector<Point> p;
    long double area;

    void operator=(Polygon t);
    void generateArea();
};

int cmpD(long double x, long double y);
Polygon makePolygon(vector<Point> p);
Point makePoint(long double x, long double y);

int main()
{
    int n;
    vector<Point> points;
    Polygon pol;

    fin >> n;
    points.resize(n);

    for(int i = 0; i < n; i++)
    {
        long double x, y;

        fin >> x >> y;

        points[i] = makePoint(x, y);
    }

    pol = makePolygon(points);

    fout << fixed << setprecision(6) << (long long)(pol.area * 1000000) / 1000000.0;

    return 0;
}

int cmpD(long double x, long double y)
{
    if(-margin < x - y && x - y < margin)
        return 0;
    
    if(x - y < margin)
        return -1;
    
    return 1;
}
void Point::operator=(Point t)
{
    this->x = t.x;
    this->y = t.y;
}
void Polygon::operator=(Polygon t)
{
    this->p = t.p;
    this->generateArea();
}
void Polygon::generateArea()
{
    Point p1, p2;
    vector<Point> &p = this->p;
    long double area_ = 0;

    for(int i = 0; i < p.size(); i++)
    {
        p1 = p[i % p.size()];
        p2 = p[(i + 1) % p.size()];

        area_ += (p1.y + p2.y) * (p1.x - p2.x);
    }

    this->area = area_ / 2;
}
Polygon makePolygon(vector<Point> p)
{
    Polygon temp;
    temp.p = p;
    return temp;
}
Point makePoint(long double x, long double y)
{
    Point temp;
    temp.x = x;
    temp.y = y;
    return temp;
}