Advertisement
nna42799

Untitled

Mar 8th, 2024 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using std::cin, std::cout, std::endl;
  7. using std::string;
  8. using std::vector, std::sort;
  9. using LL = long long;
  10. using namespace std;
  11.  
  12. const char endq = '\n';
  13.  
  14. class Rect;
  15. void combineTwoRect(const Rect &rect1, const Rect &rect2, Rect res[]);
  16.  
  17. class Rect
  18. {
  19. public:
  20.     int width = 0;
  21.     int length = 0;
  22.  
  23.     // constructor
  24.     Rect(int x, int y)
  25.     {
  26.         if (x > y)
  27.         {
  28.             length = x;
  29.             width = y;
  30.         }
  31.         else
  32.         {
  33.             length = y;
  34.             width = x;
  35.         }
  36.     }
  37.  
  38.     Rect()
  39.     {
  40.         ;
  41.     }
  42.  
  43.     bool check(const Rect &rect1, const Rect &rect2)
  44.     {
  45.         // cout << "DEBUG:" << endl;
  46.         // cout << rect1 << endl;
  47.         // cout << rect2 << endl;
  48.         // if one of the edge is greater then the length
  49.         // then it would be impossible
  50.         int maxEdge = max({rect1.length,
  51.                            rect1.width,
  52.                            rect2.length,
  53.                            rect2.width});
  54.  
  55.         if (maxEdge > length)
  56.         {
  57.             return false;
  58.         }
  59.  
  60.         Rect rectList[4];
  61.  
  62.         combineTwoRect(rect1, rect2, rectList);
  63.  
  64.         for (int i = 0; i < 4; ++i)
  65.         {
  66.             if (canContain(rectList[i]))
  67.             {
  68.                 return true;
  69.             }
  70.         }
  71.  
  72.         return false;
  73.     }
  74.  
  75.     bool canContain(Rect &rect)
  76.     {
  77.         return (length >= rect.length && width >= rect.width);
  78.     }
  79.  
  80.     bool operator<(const Rect &anoRect)
  81.     {
  82.         if (length != anoRect.length)
  83.         {
  84.             return length > anoRect.length;
  85.         }
  86.         return width > anoRect.width;
  87.     }
  88.  
  89.     friend ostream &operator<<(ostream &os, const Rect &rect)
  90.     {
  91.         os << "<Rect: L: " << rect.length << "  W:" << rect.width << ">";
  92.         return os;
  93.     }
  94. };
  95.  
  96. // ostream &operator<<(ostream &os, const Rect &rect)
  97. // {
  98. //     os << "<Rect: L: " << rect.length << "  W:" << rect.width << ">";
  99. //     return os;
  100. // }
  101.  
  102. // return a list contains 4 rect
  103. void combineTwoRect(const Rect &rect1, const Rect &rect2, Rect res[])
  104. {
  105.     res[0] = Rect(rect1.length + rect2.length, max(rect1.width, rect2.width));
  106.     res[1] = Rect(rect1.length + rect2.width, max(rect1.width, rect2.length));
  107.     res[2] = Rect(rect1.width + rect2.length, max(rect1.length, rect2.width));
  108.     res[3] = Rect(rect1.width + rect2.width, max(rect1.length, rect2.length));
  109. }
  110.  
  111. int main()
  112. {
  113.     int count;
  114.     cin >> count;
  115.  
  116.     int tmp1, tmp2;
  117.  
  118.     vector<Rect> rectList;
  119.  
  120.     for (int i = 0; i < count; ++i)
  121.     {
  122.         cin >> tmp1 >> tmp2;
  123.         rectList.push_back(Rect(tmp1, tmp2));
  124.     }
  125.  
  126.     sort(rectList.begin(), rectList.end());
  127.  
  128.     // for (auto x : rectList)
  129.     // {
  130.     //     cout << x << endl;
  131.     // }
  132.  
  133.     long long availableCombine = 0;
  134.  
  135.     for (int i = 0; i < count - 2; ++i)
  136.     {
  137.         for (int j = i + 1; j < count - 1; ++j)
  138.         {
  139.             for (int k = j + 1; k < count; ++k)
  140.             {
  141.                 if (rectList[i].check(rectList[j], rectList[k]))
  142.                 {
  143.                     ++availableCombine;
  144.                 }
  145.             }
  146.         }
  147.     }
  148.  
  149.     cout << availableCombine;
  150.     return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement