Advertisement
Alex_tz307

Aria unui poligon

Dec 17th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define x first
  3. #define y second
  4.  
  5. using namespace std;
  6. using ld = long double;
  7.  
  8. ifstream fin("ariapoligonsimplu.in");
  9. ofstream fout("ariapoligonsimplu.out");
  10.  
  11. int main() {
  12.     int N;
  13.     fin >> N;
  14.     vector<pair<ld,ld>> a(N + 1);
  15.     for(auto &x : a)
  16.         fin >> x.x >> x.y;
  17.     a[N] = a[0];
  18.     ld sol = 0;
  19.     for(int i = 0; i < N; ++i)
  20.         sol += (a[i].x * a[i + 1].y - a[i + 1].x * a[i].y);
  21.     fout << fixed << setprecision(1) << fabs(sol / 2.0);
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement