Pagini recente » Cod sursa (job #858151) | Cod sursa (job #690191) | Cod sursa (job #2216962) | Cod sursa (job #2609980) | Cod sursa (job #2417367)
#include <fstream>
#include <iomanip>
#include <vector>
typedef struct
{
long double x,y;
} Punct;
std::vector <Punct> P;
double modul(long double x)
{
if(x<0)
x=-x;
return x;
}
double Arie_triunghi(Punct a,Punct b,Punct c)
{
return ((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y))/2;
}
double Arie_convex( int n)
{
long double arie=0;
for(int i=2; i<n; i++)
arie=arie+Arie_triunghi(P[1],P[i],P[i+1]);
return arie;
}
int main()
{
int n;
std::ifstream fin("aria.in");
fin>>n;
for(int i=0; i<n; i++)
{
long double a,b;
fin>>a>>b;
P.push_back(Punct());
P[i].x=a;
P[i].y=b;
}
P.push_back(Punct());
P[n]=P[0];
std::ofstream fout("aria.out");
fout<<std::fixed<<std::setprecision(5)<<Arie_convex(n);
}