Pagini recente » Cod sursa (job #2846193) | Cod sursa (job #1489880) | Cod sursa (job #841850) | Cod sursa (job #952055) | Cod sursa (job #2558419)
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
ifstream f ("aria.in");
ofstream g ("aria.out");
int n;
long double AriaPoligon;
struct punct {
int x, y;
}puncte[100015];
long double distanta (int x, int y, int xx, int yy)
{
long double rez;
rez = sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy));
return rez;
}
long double ariatirunghi (int x, int y, int x2, int y2, int x3, int y3)
{
long double a, b, c, p, rez;
a = distanta(x, y, x2, y2);
b = distanta(x2, y2, x3, y3);
c = distanta(x, y, x3, y3);
p = (a + b + c) / 2;
rez = sqrt(p * (p - a) * (p - b) * (p - c));
return rez;
}
int main()
{
int i;
int x, y, x2, y2, x3, y3;
f >> n;
for (i=1; i<=n; i++)
{
f >> puncte[i].x;
f >> puncte[i].y;
}
for (i=3; i<=n; i++)
{
x = puncte[1].x;
y = puncte[1].y;
x2 = puncte[i-1].x;
y2 = puncte[i-1].y;
x3 = puncte[i].x;
y3 = puncte[i].y;
AriaPoligon += ariatirunghi(x, y, x2, y2, x3, y3);
}
g << fixed << setprecision(6) << AriaPoligon;
return 0;
}