#include <bits/stdc++.h>
using namespace std;
#define dim 100002
struct punct
{
int x, y;
};
struct punct2
{
long double x, y;
};
punct2 P[dim];
ifstream f("aria.in");
ofstream g("aria.out");
int verifica(punct p, punct p1, punct p2) // 0 = pe dreapta, + = in stanga, - = in dreapta
{
return (p.y - p1.y) * (p2.x - p1.x) - (p.x - p1.x) * (p2.y - p1.y);
}
int apartine(punct p, punct p1, punct p2) //daca punctul apartine segmentului <=> verifica = 0 si apartine dreptunghiului format de p1, p2
{
if (p1.x == p2.x)
if (p.y >= min(p1.y, p2.y) && p.y <= max(p1.y, p2.y))
return 1;
else
return 0;
if(p.x >= min(p1.x, p2.x) && p.x <= max(p1.x, p2.x))
return 1;
return 0;
}
void punct_segment()
{
int n, i, rez;
punct a, b, x;
f>>n;
f>>a.x>>a.y>>b.x>>b.y;
for (i=1;i<=n;i++)
{
f>>x.x>>x.y;
rez = verifica(x, a, b);
if (rez == 0)
if (apartine(x, a, b))
g<<"Este pe segment\n";
else
g<<"Nu este pe segment\n";
else
g<<rez<<"\n";
}
}
int ceas_trig(punct p0, punct p1, punct p2)
{
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y); // determinant
}
void segment_segment()
{
punct a, b;
f>>a.x>>a.y>>b.x>>b.y;
if (ceas_trig({0,0}, a, b) > 0)
g<<"Intoarcere stanga\n";
else if(ceas_trig({0,0}, a, b) < 0)
g<<"Intoarcere dreapta\n";
else
g<<"Coliniare\n";
}
int respingere_rapida(punct p1, punct p2, punct p3, punct p4) //nu se intersecteaza dreptunghiurile
{
int x1, x2, y1, y2, x3, x4, y3, y4;
x1 = min(p1.x, p2.x); x2 = max(p1.x, p2.x);
y1 = min(p1.y, p2.y); y2 = max(p1.y, p2.y);
x3 = min(p3.x, p4.x); x4 = max(p3.x, p4.x);
y3 = min(p3.y, p4.y); y4 = max(p3.y, p4.y);
return !(x2>=x3 && x4>=x1 && y2>=y3 && y4>=y1);
}
int verific_intersectie(punct p1, punct p2, punct p3, punct p4)
{
if (ceas_trig(p1, p2, p3) * ceas_trig(p1, p2, p4) > 0) //in acelasi semiplan fata de dreapta p1p2
return 0;
if (ceas_trig(p3, p4, p1) * ceas_trig(p3, p4, p2) > 0) //in acelasi semiplan fata de dreapta p3p4
return 0;
return 1;
}
void intersectie_segmente()
{
punct a, b, c, d;
f>>a.x>>a.y>>b.x>>b.y;
f>>c.x>>c.y>>d.x>>d.y;
if (verific_intersectie(a, b, c, d))
g<<"Se intersecteaza\n";
else
g<<"Nu se intersecteaza\n";
}
long double Arie_Triunghi(punct2 a, punct2 b, punct2 c)
{
return (abs((long double)(b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y))) / 2; //determinant b-a, c-a
}
void arie_triunghi()
{
punct2 a, b, c;
f>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
g<<Arie_Triunghi(a, b, c)<<"\n";
}
long double arie_convex(punct2 P[dim], int n)
{
long double arie = 0;
int i;
for (i=2;i<n;i++)
arie += Arie_Triunghi(P[1], P[i], P[i+1]);
return arie;
}
void arie_poligonConvex()
{
int n, i;
//punct2 P[dim];
f>>n;
for (i=1;i<=n;i++)
f>>P[i].x>>P[i].y;
P[0] = P[n];
P[n+1] = P[1];
g<<fixed<<setprecision(5)<<arie_convex(P, n)<<"\n";
}
double arie_oarecare(punct P[dim], int n)
{
double arie = 0;
int i;
for (i=1;i<=n;i++)
arie += P[i].x * (P[i+1].y - P[i-1].y);
return abs(arie / 2);
}
void arie_poligonOarecare()
{
int n, i;
punct P[dim];
f>>n;
for (i=1;i<=n;i++)
f>>P[i].x>>P[i].y;
P[0] = P[n];
P[n+1] = P[1];
g<<arie_oarecare(P, n)<<"\n";
}
int main()
{
//pozitie punct segment
//punct_segment();
//pozitie segment fata de segment
//segment_segment();
//intersectie segmente
//intersectie_segmente();
//arie triunghi
//arie_triunghi();
//arie poligon convex
arie_poligonConvex();
//arie poligon oarecare
//arie_poligonOarecare();
f.close();
g.close();
return 0;
}