Pagini recente » Cod sursa (job #3000733) | Cod sursa (job #2259907) | Cod sursa (job #2976062) | Cod sursa (job #2359608) | Cod sursa (job #2626785)
#include <stdio.h>
#include <math.h>
struct point {
int x;
int y;
} pcoord[100000];
int main() {
FILE *fin = fopen( "aria.in", "r" );
FILE *fout = fopen( "aria.out", "w" );
int n, i;
double x, y, xG, yG, area, a, b, c, p, x1, y1, x2, y2, x3, y3;
fscanf( fin, "%d", &n );
xG = yG = 0;
for ( i = 0; i < n; ++i ) {
fscanf( fin, "%lf%lf", &x, &y );
pcoord[i].x = x;
pcoord[i].y = y;
xG += x;
yG += y;
}
xG /= n;
yG /= n;
area = 0;
for ( i = 0; i < n; ++i ) {
x1 = pcoord[i].x;
y1 = pcoord[i].y;
x2 = pcoord[(i + 1) % n].x;
y2 = pcoord[(i + 1) % n].y;
x3 = xG;
y3 = yG;
a = sqrt( (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) );
b = sqrt( (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2) );
c = sqrt( (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3) );
p = (a + b + c) / 2;
area += sqrt( p * (p - a) * (p - b) * (p - c) );
}
fprintf( fout, "%.5lf", area );
fclose( fin );
fclose( fout );
return 0;
}