Cod sursa(job #1604401)

Utilizator c0rn1Goran Cornel c0rn1 Data 18 februarie 2016 11:21:23
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

int n;
struct Point{
   double x, y;
   Point(double xx = 0, double yy = 0){
      x = xx;
      y = yy;
   }
};
vector<Point> p;

double determinant(Point p1, Point p2, Point p3){
   return 1.0*(p1.x*p2.y + p1.y*p3.x + p2.x*p3.y - p2.y*p3.x - p1.y*p2.x - p1.x*p3.y);
}

void readData(){
   double x, y;
   scanf("%d\n", &n);
   for (int i = 1; i <= n; ++i){
      scanf("%lf %lf\n", &x, &y);
      p.push_back(Point(x, y));
   }
   p.push_back(p[0]);
}

double arie(){
   double a = 0;
   for (int i = 0; i < p.size() - 1; ++i)
      a = a + 0.5*determinant(Point(0, 0), p[i], p[i+1]);
   return a;
}

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

   readData();
   printf("%lf\n", arie());

   return 0;
}