Cod sursa(job #1115981)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 22 februarie 2014 11:42:30
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>

using namespace std;

const int Nmax = 100;

struct Point
{
    float x, y;

    Point(){}
    Point( float _x, float _y ) : x( _x ), y( _y ) {}

    friend istream& operator >> ( istream &f, Point &P )
    {
        f >> P.x >> P.y;
        return f;
    }
};

Point v[Nmax];
int N;

float area( Point A, Point B, Point C )
{
    return abs( A.x * B.y + B.x * C.y + C.x * A.y - B.x * A.y - C.x * B.y - A.x * C.y ) / 2.0;
}

int main()
{
    ifstream f("aria.in");
    ofstream g("aria.out");

    f >> N;

    for ( int i = 1; i <= N; ++i )
    {
        f >> v[i];
    }

    float A = 0;

    for ( int i = 2; i < N; ++i )
    {
        A += area( v[1], v[i], v[i + 1] );
    }

    g << fixed << setprecision( 7 );
    g << A << "\n";

    return 0;
}