Pagini recente » Cod sursa (job #925203) | Cod sursa (job #1332422) | Cod sursa (job #2736834) | Cod sursa (job #2588636) | Cod sursa (job #1269519)
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
ifstream fin("aria.in");
ofstream fout("aria.out");
struct punct
{
double X,Y;
punct()
{
X=Y=0.0;
}
punct(double x,double y)
{
X=x;Y=y;
}
};
struct trapez
{
punct A,B;
trapez()
{
A=punct(0.0,0.0);
B=punct(0.0,0.0);
}
trapez(punct a,punct b)
{
A=a;B=b;
}
trapez(double x1,double y1,double x2,double y2)
{
A=punct(x1,y1);
B=punct(x2,y2);
}
double aria()
{
return (A.X-B.X)*(A.Y+B.Y)/2;
};
};
int n;
double x1,y1,x0,y0,xi,yi,sol;
int main()
{
fin>>n;
fin>>xi>>yi;
x0=xi;y0=yi;
for(int i=2;i<=n;i++)
{
fin>>x1>>y1;
sol+=trapez(x0,y0,x1,y1).aria();
x0=x1;y0=y1;
}
x1=xi;y1=yi;
sol+=trapez(x0,y0,x1,y1).aria();
if(sol<=-0.00000001)sol=-sol;
fout<<fixed<<setprecision(7)<<sol;
return 0;
}