Cod sursa(job #1257617)

Utilizator mika17Mihai Alex Ionescu mika17 Data 7 noiembrie 2014 23:08:50
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <fstream>
#include <iomanip>
using namespace std;

long double areaTri(long double x0, long double y0, long double x1, long double y1) {

  /*
    | 1  0  0 |
    | 1 x0 y0 |
    | 1 x1 y1 |
   */
  return x0 * y1 - x1 * y0;
}

int main() {

  ifstream f("aria.in",ios::in);
  ofstream g("aria.out",ios::out);

  long double n;
  f >> n;
  
  long double cnt = 0.0;

  if(n > 1) {

    long double x0, y0;
    f >> x0 >> y0;
  
    long double x0s,y0s,x1,y1, xt, yt;
    x0s = x0, y0s = y0;
    f >> x1 >> y1;

    cnt += areaTri(x0, y0, x1, y1);
    for(int i = 2; i < n; i++) {
      f >> xt >> yt;
      x0 = x1, y0 = y1, x1 = xt, y1 = yt;
      cnt += areaTri(x0,y0,x1,y1);
    }
    cnt += areaTri(x1,y1,x0s,y0s);
  }

  g << fixed << setprecision(5) << cnt / 2.0 << endl;
  return 0;
}