Cod sursa(job #1812373)

Utilizator TincaMateiTinca Matei TincaMatei Data 22 noiembrie 2016 00:05:11
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <cstdio>

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

const int MAX_P = 100000;
int x[MAX_P], y[MAX_P];

int main() {
  int n, j;
  long long arie;
  FILE *fin = fopen("aria.in", "r");
  fscanf(fin, "%d", &n);
  for(int i = 0; i < n; ++i)
    fscanf(fin, "%d%d", &x[i], &y[i]);
  fclose(fin);

  arie = 0LL;
  for(int i = 0; i < n; ++i) {
    j = (i + 1) % n;
    arie = arie + det(0, 0, x[i], y[i], x[j], y[j]);
  }

  FILE *fout = fopen("aria.out", "w");
  if(arie < 0)
    arie = -arie;
  fprintf(fout, "%lld", arie / 2);
  if(arie % 2 == 1)
    fprintf(fout, ".5");
  fclose(fout);
  return 0;
}