Pagini recente » Cod sursa (job #2486133) | Cod sursa (job #2800043) | Cod sursa (job #554492) | Cod sursa (job #1653175) | Cod sursa (job #2565027)
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
ifstream fin("aria.in");
ofstream fout("aria.out");
const int N = 100000;
struct punct{
double x, y;
};
punct poly[N+1];
double abs(double x){
if(x < 0)
return -x;
return x;
}
double getAreaTriangle(punct P1, punct P2, punct P3){
double area = (P1.x * (P2.y - P3.y) - P2.x * (P1.y - P3.y) + P3.x * (P1.y - P2.y)) / 2;
return area;
}
double getAreaPoli(punct coords[], int points, punct center){
double area = 0;
for(int i=1; i<=points; i++)
area += abs(getAreaTriangle(coords[i-1], coords[i], center));
return area;
}
int main()
{
int n,i;
fin >> n;
for(i=0; i<n; i++)
fin >> poly[i].x >> poly[i].y;
poly[n] = poly[0];
fout << setprecision(5) << fixed;
fout << getAreaPoli(poly, n, poly[0]);
return 0;
}