Pagini recente » Cod sursa (job #2262478) | runda/nu | Cod sursa (job #983156) | Cod sursa (job #1179411) | Cod sursa (job #1229715)
#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;
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, "%.5lf", fabs( Sum / 2.0 ));
fclose( fin );
fclose( fout );
};