Pagini recente » Cod sursa (job #3255041) | Cod sursa (job #1689873) | Cod sursa (job #1694737) | Cod sursa (job #1956158) | Cod sursa (job #3270912)
#include <fstream>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
ifstream fin("aria.in");
ofstream fout("aria.out");
struct Point {
long double x, y;
};
int n;
vector<Point> points;
void read() {
fin >> n;
long double x, y;
for (int i = 1; i <= n; ++i) {
fin >> x >> y;
points.emplace_back(x, y);
}
}
int nextIndex(int currentIndex) {
return currentIndex == n - 1 ? 0 : currentIndex + 1;
}
long double computeDeterminant(const Point& a, const Point& b) {
return a.x * b.y - b.x * a.y;
}
void solve() {
long double area = 0;
for (int i = 0; i < n; ++i) {
area += computeDeterminant(points[i], points[nextIndex(i)]);
}
fout << fixed << setprecision(7) << area / 2.0;
}
int main() {
read();
solve();
return 0;
}