Pagini recente » Rating Raducanu Andrei (m0ment) | Statistici Alin Lupu (alupu) | Cod sursa (job #1195770) | Cod sursa (job #1281232) | Cod sursa (job #2224960)
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
const string IN_FILE = "aria.in";
const string OUT_FILE = "aria.out";
struct Point {
double x, y;
};
inline double det(const Point& a, const Point& b, const Point& c) {
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
double computeArea(const vector<Point>& polygon) {
const int n = int(polygon.size());
const Point origin = {0.0, 0.0};
double area = 0.0;
for (int i = 0; i < n; i++) {
area += det(origin, polygon[i], polygon[(i + 1) % n]);
}
return 0.5 * abs(area);
}
vector<Point> readPolygon() {
ifstream in(IN_FILE);
int n;
in >> n;
auto polygon = vector<Point>(n);
for (int i = 0; i < n; i++) {
in >> polygon[i].x >> polygon[i].y;
}
in.close();
return polygon;
}
void writeArea(const double area) {
ofstream out(OUT_FILE);
out << fixed << setprecision(5) << area << "\n";
out.close();
}
int main() {
const auto polygon = readPolygon();
const double area = computeArea(polygon);
writeArea(area);
return 0;
}