Cod sursa(job #2145863)

Utilizator andreigeorge08Sandu Ciorba andreigeorge08 Data 27 februarie 2018 17:37:09
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>

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

struct db{
    int x, y;
}a[100005];

int n;

void Citire()
{
    fin >> n;
    for(int i = 1; i <= n; i++)
        fin >> a[i].x >> a[i].y;
}
/**

i  j  1 -
x1 y1 1
x2 y2 1

i*y1 + x1 * y2 + j * x2 - y1 * x2 - i * y2 - j * x1

j(x2 - x1) - i (y2 - y1) + x1 y2 - y1 x2

*/

inline int A(int i, int j, int k)
{
    return a[i].y * (a[k].x - a[j].x) -
            a[i].x * (a[k].y - a[j].y)  +
            a[j].x * a[k].y - a[j].y * a[k].x;
}

void Rez()
{
    int arie = 0;

    for(int i = 2; i <= n - 1; i++)
        arie += abs(A(1, i, i + 1));

    fout << fixed << setprecision(6) << arie / 2.0 << "\n";
}
int main()
{
    Citire();
    Rez();
    return 0;
}