Cod sursa(job #2448527)

Utilizator georgerapeanuRapeanu George georgerapeanu Data 17 august 2019 11:49:12
Problema Aria Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <cstdio>

using namespace std;

FILE *f = fopen("aria.in","r");
FILE *g = fopen("aria.out","w");

long long det(int ax,int ay,int bx,int by,int cx,int cy){
    return 1LL * ax * (by - cy) + 1LL * bx * (cy - ay) + 1LL * cx * (ay - by);
}

int main(){

    long long arie = 0;
    int n;
    int x[21];
    int y[21];

    fscanf(f,"%d",&n);

    for(int i = 1;i <= n;i++){
        fscanf(f,"%d %d",&x[i],&y[i]);
        if(i > 1)arie += det(0,0,x[i - 1],y[i - 1],x[i],y[i]);
    }
    
    arie += det(0,0,x[n],y[n],x[1],y[1]);

    fprintf(g,"%.5f",(double)((arie < 0 ? -arie:arie) / 2));

    fclose(f);
    fclose(g);

    return 0;
}