Advertisement
Guest User

Calculate the Area

a guest
Aug 18th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. //Bismillahir Rahmanir Rahim
  2. /******Harun Or Rashid******/
  3. /***********Template Starts Here***********/
  4. #include<iostream>
  5. #include<cstdio>
  6. #include<cstring>
  7. #include<cmath>
  8. #include<cctype>
  9. #include<cstdlib>
  10. #include<string>
  11. #include<vector>
  12. #include<set>
  13. #include<stack>
  14. #include<queue>
  15. #include<map>
  16. #include<algorithm>
  17. using namespace std;
  18.  
  19. #define MEM(a,b) memset(a,b,sizeof(a))
  20. #define CLR(a) memset(a,0,sizeof(a))
  21. #define MAX(a,b) ((a)>(b)?(a):(b))
  22. #define MIN(a,b) ((a)>(b)?(b):(a))
  23. #define ABS(a) ((a)>0? (a):(-(a)))
  24. #define SQ(a) ((a)*(a))
  25. #define SZ(a) (int)a.size()
  26. #define FORN(i,n) for(i=1;i<=n;i++)
  27. #define FORAB(i,a,b) for(i=a;i<=b;i++)
  28. #define ALL(V) V.begin(),V.end()
  29. #define pb(a) push_back(a)
  30. #define pr(a) cout<<a<<endl
  31. #define pf printf
  32. #define sf scanf
  33. #define swap(a,b) (a ^= b, b ^= a, a ^= b)
  34. #define PI acos(-1)
  35. #define x first
  36. #define y second
  37. #define eps 1e-7
  38.  
  39. typedef int D;
  40. typedef long long int LLD;
  41. typedef unsigned long long int LLU;
  42. typedef vector<D> VI;
  43. typedef set<D> SI;
  44. typedef vector<D>::iterator Viti;
  45.  
  46. /***********Template Ends Here***********/
  47.  
  48. int main()
  49. {
  50.     int n,i,x1,y1,x2,y2,result;
  51.     double area=0,cross;
  52.     pair<int,int>point;
  53.     vector<pair<int,int> >V;
  54.     cin>>n;
  55.     for(i=0; i<n; i++)
  56.     {
  57.         cin>>point.x>>point.y;
  58.         V.pb(point);
  59.     }
  60.     for(i=1; i<n-1; i++)
  61.     {
  62.         x1=V[i].x-V[0].x;
  63.         y1=V[i].y-V[0].y;
  64.         x2=V[i+1].x-V[0].x;
  65.         y2=V[i+1].y-V[0].y;
  66.         cross=x1*y2-x2*y1;
  67.         area+=cross;
  68.     }
  69.     result=int(ABS(area/2));
  70.     cout<<result<<endl;
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement