Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- struct Vector2{
- int x;
- int y;
- Vector2(int x = 0, int y = 0):x(x),y(y){}
- };
- int gcd(int a, int b){
- while(a > 0 && b > 0){
- if(a > b) a -= b;
- else b -= a;
- }
- return (max(a, b));
- }
- int main(){
- Vector2 A, B, C;
- /* cout << "Ax:";
- cin >> A.x;
- cout << "Ay:";
- cin >> A.y;
- cout << "Bx:";
- cin >> B.x;
- cout << "By:";
- cin >> B.y;
- cout << "Cx:";
- cin >> C.x;
- cout << "Cy:";
- cin >> C.y;*/
- A = Vector2(3, 1);
- B = Vector2(1, 5);
- C = Vector2(5, 4);
- float area, AB, BC, CA, interior, exterior, s, total;
- Vector2 distAB, distBC, distCA, temp;
- distAB.x = abs(B.x - A.x);
- distAB.y = abs(B.y - A.y);
- distBC.x = abs(C.x - B.x);
- distBC.y = abs(C.y - B.y);
- distCA.x = abs(A.x - C.x);
- distCA.y = abs(A.y - C.y);
- exterior = gcd(distAB.x, distAB.y) + gcd(distBC.x, distBC.y) + gcd(distCA.x, distCA.y);
- AB = sqrt(distAB.x * distAB.x + distAB.y * distAB.y);
- BC = sqrt(distBC.x * distBC.x + distBC.y * distBC.y);
- CA = sqrt(distCA.x * distCA.x + distCA.y * distCA.y);
- s = (AB + BC + CA) / 2;
- area = sqrt(s * (s - AB) * (s - BC) * (s - CA));
- interior = area + 1 - exterior / 2;
- total = exterior + interior;
- cout << total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement