Pagini recente » Cod sursa (job #2894283) | Cod sursa (job #2568209) | Cod sursa (job #3218910) | Cod sursa (job #3274616) | Cod sursa (job #1088750)
#include <fstream>
#include <iostream>
#include <iterator>
#include <algorithm>
//#include <cmath>
#define MAXN 100002
using namespace std;
struct Point
{
Point() :
x(0.0),
y(0.0)
{}
Point(long double x_, long double y_) :
x(x_),
y(y_)
{}
long double x = 0.0;
long double y = 0.0;
};
istream & operator >> (istream & is, Point & p)
{
is >> p.x >> p.y;
return is;
}
ostream & operator << (ostream & os, const Point & p)
{
os << p.x << " "<< p.y;
return os;
}
Point points[MAXN];
long double computeTriangleArea(const Point & p1, const Point & p2, const Point & p3)
{
return .5 * (-p2.x * p1.y + p3.x * p1.y + p1.x * p2.y - p3.x * p2.y - p1.x * p3.y + p2.x * p3.y);
}
int main()
{
int n;
fstream fin("aria.in", fstream::in);
fstream fout("aria.out", fstream::out);
fin >> n;
//cout << n << endl;
copy_n(istream_iterator<Point>(fin), n, points);
//ostream_iterator<Point> itOut(cout, "\n");
//copy(points, points + n, itOut);
//long double pivot = -1100000.0;
long double area = points[n-1].x * points[0].y - points[0].x * points[n - 1].y;
for (int i=0; i<n - 1; ++i)
{
area += (points[i].x * points[i + 1].y - points[i + 1].x * points[i].y);
}
area *= .5;
fout << fabs(area) << "\n";
return 0;
}