Cod sursa(job #2130948)

Utilizator SolcanMihaiSolcan Mihai Andrei SolcanMihai Data 14 februarie 2018 09:25:32
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <cstdio>

using namespace std;

double arie = 0;

void addTriangle(double x1, double y1, double x2, double y2){
    double ok;

    if(x1 < x2){
        ok = -1;
    }
    else{
        ok = 1;
    }

    arie += (double)(x1 * y2 - x2 * y1) * ok;
}

int main()
{
    freopen("aria.in", "r", stdin);
    freopen("aria.out", "w", stdout);

    int n;
    double first[5];
    scanf("%d", &n);


    double x1, x2, y1, y2;

    scanf("%lf %lf", &x1, &y1);

    first[0] = x1;
    first[1] = y1;

    for(int i = 0; i < n; i++){
        x2 = x1;
        y2 = y1;
        scanf("%lf %lf", &x1, &y1);

        addTriangle(x1, y1, x2, y2);
    }

    addTriangle(first[0], first[1], x1, y1);

    printf("%lf", -arie);

    return 0;
}