Advertisement
evgenko

Untitled

Apr 7th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define x first
  3. #define y second
  4.  
  5. using namespace std;
  6.  
  7. int getsquere(pair<int, int> p1, pair<int,int> p2){
  8.         return (p1.y + p2.y) * (p2.x - p1.x);
  9. }
  10. int main() {
  11.     int N;
  12.     cin >> N;
  13.     pair<int, int> coords[N];
  14.     for (int i=0;i<N;i++){
  15.         cin >> coords[i].x;
  16.         cin >> coords[i].y;
  17.     }
  18.     int s = 0;
  19.     for (int i=0;i<N;i++){
  20.         if (i!=0){
  21.             s += getsquere(coords[i-1], coords[i]);
  22.         }else{
  23.             s += getsquere(coords[N-1], coords[0]);
  24.         }
  25.     }
  26.     printf("%.1f", fabs(((double)s)/2));
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement