Pagini recente » Cod sursa (job #642390) | Cod sursa (job #1315062) | Cod sursa (job #517507) | Cod sursa (job #2141734) | Cod sursa (job #2558641)
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
ifstream f ("aria.in");
ofstream g ("aria.out");
int n;
double AriaPoligon;
struct punct {
int x, y;
}v[100015];
void read ()
{
int i, xx, yy;
f >> n;
for (i=1; i<=n; i++)
{
f >> xx >> yy;
v[i].x = xx;
v[i].y = yy;
}
}
double aria (int x, int y, int x2, int y2, int x3, int y3)
{
double rez;
rez = fabs(x * y2 + x2 * y3 + x3 * y - x3 * y2 - x * y3 - x2 * y);
rez /= 2;
return rez;
}
void solve ()
{
int i, xx, yy, x2, y2, x3, y3;
xx = v[1].x, yy = v[1].y;
for (i=3; i<=n; i++)
{
x2 = v[i-1].x;
y2 = v[i-1].y;
x3 = v[i].x;
y3 = v[i].y;
AriaPoligon += aria(xx, yy, x2, y2, x3, y3);
}
g << fixed << setprecision(6) << AriaPoligon;
}
int main()
{
read();
solve();
return 0;
}