Cod sursa(job #1921154)

Utilizator Bot32King Max Bot32 Data 10 martie 2017 11:34:13
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("aria.in");
ofstream g("aria.out");
#define point pair<double,double>
#define x first
#define y second
#define MAXN 100001

int N,i;
vector<point>v;
double arietr(point A, point B, point C)
{
  return ((B.x-A.x)*(C.y-A.y) - (C.x-A.x) * (B.y-A.y)) /2 ;
}
double dist (point a,point b)
{
    return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
double ariaTriunghi(point a,point b,point c)
{
    double ab=dist(a,b);
    double ac=dist(a,c);
    double bc=dist(b,c);
    double p=(ab+ac+bc)/2;
    return sqrt(p*(p-ab)*(p-ac)*(p-bc));
}
double ariaPoligon()
{
    double S = 0;
    for (int i = 2; i < N ; i++ )
        S += arietr(v[1],v[i],v[i+1]);
        //S += ariaTriunghi(v[1],v[i],v[i+1]);
    return S;
}

int main()
{
    f>>N;
    v=vector<point>(N+1);
    for(i=1;i<=N;i++)
        f>>v[i].x>>v[i].y;
    freopen("aria.out","w",stdout);
    printf("%.6f ",ariaPoligon());
    return 0;
}