Cod sursa(job #1505035)

Utilizator refugiatBoni Daniel Stefan refugiat Data 18 octombrie 2015 17:58:49
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb

#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

const int NMAX = 100000;

struct punct
{
  double x, y;

  punct(double x = 0, double y = 0)
  {
    this->x = x;
    this->y = y;
  }
};

double Arie(const punct &P, const punct &B, const punct &C)
{
  return ((B.x-P.x) * (C.y-P.y) - (B.y-P.y) * (C.x-P.x)) / 2;
}

punct v[2+NMAX];

int main()
{
  freopen("aria.in", "r", stdin);
  freopen("aria.out", "w", stdout);

  int n;
  punct p = punct();

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lf%lf", &v[i].x, &v[i].y);
    p.x = min(p.x, v[i].x - 1);
    p.y = min(p.y, v[i].y - 1);
  }
  v[n+1] = v[1];

  double arieSol = 0;
  for (int i = 1; i <= n; ++i)
    arieSol += Arie(p, v[i], v[i+1]);

  printf("%lf\n", arieSol );

  return 0;
}