Cod sursa(job #2448530)

Utilizator georgerapeanuRapeanu George georgerapeanu Data 17 august 2019 11:50:52
Problema Aria Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <cstdio>

using namespace std;

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

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

int n;
double x[int(1e5) + 5];
double y[int(1e5) + 5];

int main(){

    double arie = 0;

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

    for(int i = 1;i <= n;i++){
        fscanf(f,"%lf %lf",&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",((arie < 0 ? -arie:arie) / 2));

    fclose(f);
    fclose(g);

    return 0;
}