Cod sursa(job #2863967)

Utilizator BeneIonut2208Bene Ionut-Matei BeneIonut2208 Data 7 martie 2022 14:13:49
Problema Aria Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

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

struct punct
{
    double x, y;
};

int n;

punct pct[100005];
/**
xA yA 1 xA yA
xB yB 1 xB yB
xC yC 1 xC yC

= xA * yB + yA * xC + xB * yC - yA * xB - xA * yC - xC * yB
**/

void citire()
{
    fin >> n;
    for(int i = 0; i < n; i++)
        fin >> pct[i].x >> pct[i].y;
}

double det(punct A, punct B, punct C)
{
    return A.x * B.y + A.y * C.x + B.x * C.y - A.y * B.x - A.x * C.y - C.x * B.y;
}




int main()
{
    double suma = 0;
    punct p1, p2, p3;
    p1.x = 0;
    p1.y = 0;
    citire();
    for(int i = 0; i < n - 2; i++)
    {
        suma += 0.5 * det(p1, pct[i], pct[i + 1]);
    }
    suma += abs(det(p1, pct[n - 1], pct[0]));
    fout << abs(suma);
    return 0;
}