Pagini recente » Cod sursa (job #817171) | Cod sursa (job #2600004) | Cod sursa (job #11622) | Cod sursa (job #2122375) | Cod sursa (job #2533105)
#include <fstream>
#include <vector>
#define INPUT_FILE "aria.in"
#define OUTPUT_FILE "aria.out"
using Point = std::pair<float, float>;
std::vector<Point> points;
void Read()
{
std::fstream in(INPUT_FILE, std::ios_base::in);
if (in.is_open())
{
int n;
float x, y;
in >> n;
for (int i = 1; i <= n; i++)
{
in >> x >> y;
points.emplace_back(x, y);
}
in.close();
}
}
float CrossProduct(const Point& p1, const Point& p2)
{
return (p1.first * p2.second - p1.second * p2.first);
}
int main()
{
Read();
float area = 0.f;
for (size_t indx = 0; indx < points.size(); ++indx)
{
const Point& firstPoint = points[indx];
const Point& secondPoint = (indx == points.size() - 1) ? points[0] : points[indx + 1];
area += CrossProduct(firstPoint, secondPoint);
}
std::fstream out(OUTPUT_FILE, std::ios_base::out);
if (out.is_open())
{
out << 0.5f * area << "\n";
out.close();
}
return 0;
}