Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using std::cin, std::cout, std::endl;
- using std::string;
- using std::vector, std::sort;
- using LL = long long;
- using namespace std;
- const char endq = '\n';
- class Rect;
- void combineTwoRect(const Rect &rect1, const Rect &rect2, Rect res[]);
- class Rect
- {
- public:
- int width = 0;
- int length = 0;
- // constructor
- Rect(int x, int y)
- {
- if (x > y)
- {
- length = x;
- width = y;
- }
- else
- {
- length = y;
- width = x;
- }
- }
- Rect()
- {
- ;
- }
- bool check(const Rect &rect1, const Rect &rect2)
- {
- // cout << "DEBUG:" << endl;
- // cout << rect1 << endl;
- // cout << rect2 << endl;
- // if one of the edge is greater then the length
- // then it would be impossible
- int maxEdge = max({rect1.length,
- rect1.width,
- rect2.length,
- rect2.width});
- if (maxEdge > length)
- {
- return false;
- }
- Rect rectList[4];
- combineTwoRect(rect1, rect2, rectList);
- for (int i = 0; i < 4; ++i)
- {
- if (canContain(rectList[i]))
- {
- return true;
- }
- }
- return false;
- }
- bool canContain(Rect &rect)
- {
- return (length >= rect.length && width >= rect.width);
- }
- bool operator<(const Rect &anoRect)
- {
- if (length != anoRect.length)
- {
- return length > anoRect.length;
- }
- return width > anoRect.width;
- }
- friend ostream &operator<<(ostream &os, const Rect &rect)
- {
- os << "<Rect: L: " << rect.length << " W:" << rect.width << ">";
- return os;
- }
- };
- // ostream &operator<<(ostream &os, const Rect &rect)
- // {
- // os << "<Rect: L: " << rect.length << " W:" << rect.width << ">";
- // return os;
- // }
- // return a list contains 4 rect
- void combineTwoRect(const Rect &rect1, const Rect &rect2, Rect res[])
- {
- res[0] = Rect(rect1.length + rect2.length, max(rect1.width, rect2.width));
- res[1] = Rect(rect1.length + rect2.width, max(rect1.width, rect2.length));
- res[2] = Rect(rect1.width + rect2.length, max(rect1.length, rect2.width));
- res[3] = Rect(rect1.width + rect2.width, max(rect1.length, rect2.length));
- }
- int main()
- {
- int count;
- cin >> count;
- int tmp1, tmp2;
- vector<Rect> rectList;
- for (int i = 0; i < count; ++i)
- {
- cin >> tmp1 >> tmp2;
- rectList.push_back(Rect(tmp1, tmp2));
- }
- sort(rectList.begin(), rectList.end());
- // for (auto x : rectList)
- // {
- // cout << x << endl;
- // }
- long long availableCombine = 0;
- for (int i = 0; i < count - 2; ++i)
- {
- for (int j = i + 1; j < count - 1; ++j)
- {
- for (int k = j + 1; k < count; ++k)
- {
- if (rectList[i].check(rectList[j], rectList[k]))
- {
- ++availableCombine;
- }
- }
- }
- }
- cout << availableCombine;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement