Pagini recente » Cod sursa (job #3127614) | Cod sursa (job #1296968) | Cod sursa (job #2106544) | Istoria paginii utilizator/moscugeorge | Cod sursa (job #2009128)
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <sstream>
#include <cmath>
#include <iomanip>
#define ld long double
using namespace std;
ifstream fin("aria.in");
ofstream fout("aria.out");
const int NLIM = 1e5 + 10;
int N;
int orient( int x1, int yy1, int x2, int y2, int x3, int y3 )
{
int v = ( y2 - yy1 )*( x3 - x2 ) - ( y3 - y2 )*( x2 - x1 );
/*/
cout << x1 << " " << y1 << "\n";
cout << x2 << " " << y2 << "\n";
cout << x3 << " " << y3 << "\n";
cout << v << "\n-----------\n";
//*/
if( v > 0 )
return -1;
else if( v < 0 )
return 1;
else
return 0;
}
int x1, yy1;
int lx, ly;
int px = 0;
int py = 0;
ld res = 0;
int main()
{
fin >> N;
fin >> lx >> ly;
for( int i = 1; i < N; ++i )
{
int x, y;
fin >> x >> y;
ld a = sqrt( ( x - px ) * ( x - px ) + ( y - py ) * ( y - py ) );
ld b = sqrt( ( lx - px ) * ( lx - px ) + ( ly - py ) * ( ly - py ) );
ld c = sqrt( ( lx - x ) * ( lx - x ) + ( ly - y ) * ( ly - y ) );
ld T;
ld s = ( a + b + c ) / 2;
T = sqrt( s*( s - a )*( s - b )*( s - c ) );
//cout << a << " " << b << " " << c << " " << T << "\n";
int o = orient( px, py, lx, ly, x, y );
if( o == 1 )
{
res += T;
//cout << "-\n";
}
else if( o == -1 )
{
res -= T;
// cout << "+\n";
}
if( i == 1 )
{
x1 = lx;
yy1 = ly;
}
lx = x;
ly = y;
}
int x, y;
x = x1;
y = yy1;
ld a = sqrt( ( x - px ) * ( x - px ) + ( y - py ) * ( y - py ) );
ld b = sqrt( ( lx - px ) * ( lx - px ) + ( ly - py ) * ( ly - py ) );
ld c = sqrt( ( lx - x ) * ( lx - x ) + ( ly - y ) * ( ly - y ) );
ld T;
ld s = ( a + b + c ) / 2;
T = sqrt( s*( s - a )*( s - b )*( s - c ) );
// cout << a << " " << b << " " << c << " " << T << "\n";
int o = orient( px, py, lx, ly, x, y );
if( o == 1 )
{
res += T;
// cout << "-\n";
}
else if( o == -1 )
{
res -= T;
//cout << "+\n";
}
fout << setprecision( 5 ) << res << "\n";
return 0;
}