Cod sursa(job #2131330)

Utilizator SolcanMihaiSolcan Mihai Andrei SolcanMihai Data 14 februarie 2018 17:17:34
Problema Aria Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <cstdio>

using namespace std;

double arie = 0;

double abs(double x){
    if(x < 0){
        return -x;
    }
    return x;
}

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

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

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

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);

//    x1 += 1000;
//    y1 += 1000;

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

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

//        x1 += 1000;
//        y1 += 1000;

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

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

    double m = -arie / 2;



    printf("%lf", m);

    return 0;
}