SHARE
TWEET

UFO

rontav Jun 22nd, 2015 (edited) 323 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. struct Vector2{
  7.     int x;
  8.     int y;
  9.     Vector2(int x = 0, int y = 0):x(x),y(y){}
  10. };
  11.  
  12. int gcd(int a, int b){
  13.     while(a > 0 && b > 0){
  14.         if(a > b) a -= b;
  15.         else b -= a;
  16.     }
  17.     return (max(a, b));
  18. }
  19.  
  20. int main(){
  21.     Vector2 A, B, C;
  22.    
  23.     /* cout << "Ax:";
  24.     cin >> A.x;
  25.     cout << "Ay:";
  26.     cin >> A.y;
  27.     cout << "Bx:";
  28.     cin >> B.x;
  29.     cout << "By:";
  30.     cin >> B.y;
  31.     cout << "Cx:";
  32.     cin >> C.x;
  33.     cout << "Cy:";
  34.     cin >> C.y;*/
  35.    
  36.     A = Vector2(3, 1);
  37.     B = Vector2(1, 5);
  38.     C = Vector2(5, 4);
  39.  
  40.     float area, AB, BC, CA, interior, exterior, s, total;
  41.     Vector2 distAB, distBC, distCA, temp;
  42.  
  43.     distAB.x = abs(B.x - A.x);
  44.     distAB.y = abs(B.y - A.y);
  45.     distBC.x = abs(C.x - B.x);
  46.     distBC.y = abs(C.y - B.y);
  47.     distCA.x = abs(A.x - C.x);
  48.     distCA.y = abs(A.y - C.y);
  49.  
  50.     exterior = gcd(distAB.x, distAB.y) + gcd(distBC.x, distBC.y) + gcd(distCA.x, distCA.y);
  51.    
  52.     AB = sqrt(distAB.x * distAB.x + distAB.y * distAB.y);
  53.     BC = sqrt(distBC.x * distBC.x + distBC.y * distBC.y);
  54.     CA = sqrt(distCA.x * distCA.x + distCA.y * distCA.y);
  55.  
  56.     s = (AB + BC + CA) / 2;
  57.     area = sqrt(s * (s - AB) * (s - BC) * (s - CA));
  58.     interior = area + 1 - exterior / 2;
  59.  
  60.     total = exterior + interior;
  61.  
  62.     cout << total;
  63. }
RAW Paste Data
Top