Pagini recente » Cod sursa (job #1557319) | Cod sursa (job #219934) | Cod sursa (job #934982) | Cod sursa (job #3277787) | Cod sursa (job #1795501)
#include <fstream>
#include <iomanip>
using namespace std;
ofstream fout("aria.out");
ifstream fin("aria.in");
struct point{
long double x;
long double y;
}v[4];
long double area(point a, point b, point c)
{
a.x -= c.x;
b.x -= c.x;
a.y -= c.y;
b.y -= c.y;
long double d=(long double)(a.x * b.y - a.y * b.x)/(long double)2;
if(d >= 0)
{
return d;
}
else
{
return 0 - d;
}
}
int main()
{
int n, i;
long double s = 0;
fin >> n;
for(i = 1; i <= n; i++)
{
if(i < 3)
{
fin >> v[i].x >> v[i].y;
}
if(i > 3)
{
v[2] = v[3];
fin >> v[3].x >> v[3].y;
s += area(v[1],v[2],v[3]);
}
if(i == 3)
{
fin >> v[3].x >> v[3].y;
s += area(v[1],v[2],v[3]);
}
}
fout << setprecision(5) << fixed << s;
return 0;
}