Cod sursa(job #1229708)

Utilizator thinkphpAdrian Statescu thinkphp Data 17 septembrie 2014 23:02:59
Problema Aria Scor 70
Compilator c Status done
Runda Arhiva educationala Marime 1.06 kb
#include <stdio.h>
#include <math.h>
#include <assert.h>
#define MAX 100005
#define FIN "aria.in"
#define FOUT "aria.out"

struct Point {

       double x;
       double y; 
};

int N;

double Sum = 0;

struct Point vector_of_points[ MAX ];

FILE *fin, *fout;

void readAndSolve();

int main() {

    readAndSolve();

    return 0; 
};

void readAndSolve() {

      int i;

      fin = fopen(FIN, "r");
      fout = fopen(FOUT, "w");

      fscanf(fin, "%d", &N);

      assert(1<=N && N <= 100000);

      for(i = 0; i < N; i++) {

           fscanf(fin, "%lf %lf", &vector_of_points[i].x, &vector_of_points[i].y); 
      }

      vector_of_points[ N ] = vector_of_points[ 0 ];

      // | 0   0  1 |
      // | x2 y2  1 | * 1 / 2 in fabs  
      // | x1 y1  1 |

      for(i = 0; i < N; i++) {

          Sum += vector_of_points[ i ].x * vector_of_points[ i + 1 ].y - vector_of_points[ i ].y * vector_of_points[ i + 1 ].x;
      }

      fprintf(fout, "%lf", fabs( Sum / 2.0 ));

      fclose( fin ); 
      fclose( fout ); 
};