Cod sursa(job #1876031)

Utilizator Andrei0308Andrei Loghin Andrei0308 Data 11 februarie 2017 21:42:20
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <fstream>
#define NMAX 100005
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
ifstream fin("aria.in");
ofstream fout("aria.out");
struct varf
{
    double x,y;
} v[NMAX];
bool compar (varf a, varf b)
{
    return a.x<b.x || (a.x==b.x && a.y<b.y);
}
int n;
double atot, atc,a,b,c,p;
int main()
{
    int i;
    fin>>n;
    for(i=1; i<=n; i++)
        fin>>v[i].x>>v[i].y;
    sort(v+1, v+n+1,compar);
    v[n+1]=v[1];
    for(i=2; i<=n; i++)
    {
        a=sqrt( (v[1].x - v[i].x) * (v[1].x - v[i].x) + (v[1].y - v[i].y) * (v[1].y - v[i].y) );
        b=sqrt( (v[i].x - v[i+1].x) * (v[i].x - v[i+1].x) + (v[i].y - v[i+1].y) * (v[i].y - v[i+1].y) );
        c=sqrt( (v[i+1].x - v[1].x) * (v[i+1].x - v[1].x) + (v[i+1].y - v[1].y) * (v[i+1].y - v[1].y) );
        p=(a+b+c) / 2;
        atc= sqrt( p * (p-a) * (p-b) * (p-c) );
        atot+=atc;
    }
    fout<<std::fixed<<std::setprecision(6)<<atot;
    fout.close();
    fin.close();
    return 0;
}