Advertisement
Hippskill

Untitled

Jan 19th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.81 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include<stdio.h>
  3. #include<iostream>
  4. #include<vector>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<memory.h>
  8. #include<map>
  9. #include<set>
  10. #include<queue>
  11. #include<list>
  12. #include<sstream>
  13. #include<cstring>
  14. #include<numeric>
  15. #include<limits.h>
  16. using namespace std;
  17.  
  18.  
  19. struct point {
  20. private: double x, y;
  21. public:
  22.     point() : x(0), y(0) {}
  23.     point(double x, double y) : x(x), y(y) {}
  24.  
  25.     void scan() {
  26.         scanf("%lf%lf", &x, &y);
  27.     }
  28.     point operator+ (const point & P) const {
  29.         return point(x + P.x, y + P.y);
  30.     }
  31.  
  32.     point operator- (const point & P) const {
  33.         return point(x - P.x, y - P.y);
  34.     }
  35.  
  36.     point operator/ (double k) const {
  37.         return point(x / k, y / k);
  38.     }
  39.    
  40.     bool operator== (const point & P) const {
  41.         return x == P.x && y == P.y;
  42.     }
  43.  
  44.     double operator*(const point & P) const {
  45.         return x * P.y - y * P.x;
  46.     }
  47.  
  48.     point operator*(double k) const{
  49.         return point(x * k, y * k);
  50.     }
  51.  
  52.     double operator%(const point & p) const{
  53.         return x * p.x + y * p.y;
  54.     }
  55.  
  56.  
  57.     double dist(const point & P) const {
  58.         point r = P - *this;
  59.         return hypot(r.x, r.y);
  60.     }
  61.  
  62.  
  63.     double getAngle(point u) const{
  64.         point v = *this;
  65.         return atan2(v * u, v % u);
  66.     }
  67.  
  68.     point rotate() const{
  69.         return point(-y, x);
  70.     }
  71.  
  72.     point rotate(double cosa, double sina) const
  73.     {
  74.         point v = *this;
  75.         point u = v.rotate();
  76.         point w = v * cosa + u * sina;
  77.         return w;
  78.     }
  79.     point rotate(double alpha) const{
  80.         return rotate(cos(alpha), sin(alpha));
  81.     }
  82.  
  83.  
  84. };
  85.  
  86. double triangleArea(point & A, point & B, point & C) {
  87.     return abs((A - B) * (C - B)) * 0.5;
  88. }
  89.  
  90.  
  91.  
  92. point f[3];
  93. point s[3];
  94.  
  95.  
  96. bool is0() {
  97.     for (int i = 0; i < 3; i++) {
  98.         for (int j = 0; j < 3; j++) {
  99.             for (int z = 0; z < 3; z++) {
  100.                 if (i == j || j == z || z == i) continue;
  101.                 if (f[i] == s[0] && f[j] == s[1] && f[z] == s[2])
  102.                     return true;
  103.             }
  104.         }
  105.     }
  106.     return false;
  107. }
  108.  
  109. bool isEquals() {
  110.     double sidef[3]{ f[0].dist(f[1]), f[1].dist(f[2]), f[0].dist(f[2]) };
  111.     double sides[3]{ s[0].dist(s[1]), s[1].dist(s[1]), s[0].dist(s[2]) };
  112.     for (int i = 0; i < 3; i++) {
  113.         for (int j = 0; j < 3; j++) {
  114.             for (int z = 0; z < 3; z++) {
  115.                 if (i == j || j == z || z == i) continue;
  116.                 if (sidef[i] == sides[0] && sidef[j] == sides[1] && sidef[z] == sides[2])
  117.                     return true;
  118.             }
  119.         }
  120.     }
  121.     return false;
  122. }
  123.  
  124.  
  125. int idMax(point A, point B, point C) {
  126.     double angles[3]{ A.getAngle(B), B.getAngle(C), A.getAngle(C) };
  127.     double mx = angles[0];
  128.     int id = 0;
  129.     for (int i = 1; i < 3; i++) {
  130.         if (mx < angles[i]) {
  131.             mx = angles[i];
  132.             id = i;
  133.         }
  134.     }
  135.     return id;
  136. }
  137.  
  138. int idMin(point A, point B, point C) {
  139.     double angles[3]{ A.getAngle(B), B.getAngle(C), A.getAngle(C) };
  140.     double mx = angles[0];
  141.     int id = 0;
  142.     for (int i = 1; i < 3; i++) {
  143.         if (mx > angles[i]) {
  144.             mx = angles[i];
  145.             id = i;
  146.         }
  147.     }
  148.     return id;
  149. }
  150.  
  151. int main(){
  152.     for (int i = 0; i < 3; i++) {
  153.         f[i].scan();
  154.     }
  155.    
  156.     for (int i = 0; i < 3; i++) {
  157.         s[i].scan();
  158.     }
  159.  
  160.     double fs = triangleArea(f[0], f[1], f[2]);
  161.     double ss = triangleArea(s[0], s[1], s[2]);
  162.  
  163.  
  164.     if (fs != ss) {
  165.         printf("5");
  166.         return 0;
  167.     }
  168.  
  169.     if (is0) {
  170.         printf("0");
  171.         return 0;
  172.     }
  173.  
  174.     if (!isEquals()) {
  175.         printf("4");
  176.         return 0;
  177.     }
  178.  
  179.     double len = f[0].dist(s[0]);
  180.     bool p = false;
  181.  
  182.     for (int i = 1; i < 3; i++) {
  183.         if (f[i].dist(s[i]) != len) {
  184.             p = false;
  185.         }
  186.     }
  187.  
  188.     if (p) {
  189.         printf("1");
  190.         return 0;
  191.     }
  192.  
  193.  
  194.     int mf = idMax(f[0], f[1], f[2]);
  195.     int ms = idMax(s[0], s[1], s[2]);
  196.  
  197.     for (int i = 0; i < 3; i++) {
  198.         f[i] = f[i] - f[mf];
  199.         s[i] = s[i] - s[ms];
  200.     }
  201.    
  202.     int mxf = idMin(f[0], f[1], f[2]);
  203.     int mxs = idMin(s[0], s[1], s[2]);
  204.  
  205.     double alpha = f[mxf].getAngle(s[mxs]);
  206.  
  207.     for (int i = 1; i < 3; i++) {
  208.         f[i].rotate(alpha);
  209.         s[i].rotate(alpha);
  210.     }
  211.    
  212.     if (isEquals()) {
  213.         printf("2");
  214.     }
  215.     else {
  216.         printf("3");
  217.     }
  218.  
  219.     return 0;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement