Cod sursa(job #2014663)

Utilizator Stefan_RaduStefan Radu Stefan_Radu Data 24 august 2017 12:02:02
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <fstream>
#include <vector>
#include <iomanip>

using namespace std;

ifstream cin("aria.in");
ofstream cout("aria.out");

long double det(pair < long double, long double > a, pair < long double, long double > b, pair < long double, long double > c) {
  long double d = (a.first * b.second) + (b.first * c.second) + (c.first * a.second) -
          (a.second * b.first) - (b.second * c.first) - (c.second * a.first);

  return d / 2.0f;
}

int main() {
  int n;
  cin >> n;
  vector < pair < long double, long double > > v(n + 1);
  cout << fixed << setprecision(8); 

  long double aria = 0.0f;
  for (int i = 1; i <= n ; i ++) {
    long double x, y;
    cin >> x >> y;
    v[i] = {x, y};
  }

  for (int i = 2; i <= n - 1; i ++) {
    aria += det(v[1], v[i], v[i + 1]); 
  }

  cout << aria << '\n';
}