UVa1587
参考了一下其它博主的思路:
- 交换每个长方形的宽和高,使宽小于高
- 对6个长方形进行排序,使宽小的排在前面,宽相同则高小的排在前面
- 如果两两成一对,并且
0
和2
的宽度相同、2
和4
的高度相同、0
的高度和4
的宽度相同则可以构成长方体
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct Rect
{
int width;
int height;
}Rect;
bool operator<(const Rect &r1, const Rect &r2)
{
if (r1.width < r2.width) return true;
else if (r1.width == r2.width){
if (r1.height < r2.height) return true;
else return false;
}
else return false;
}
bool operator==(const Rect &r1, const Rect &r2)
{
return r1.width == r2.width && r1.height == r2.height;
}
int main()
{
vector<Rect> vecRec;
string strLine;
Rect rect;
while (cin >> rect.width >> rect.height){
if (rect.width > rect.height){
rect.width ^= rect.height ^= rect.width ^= rect.height;
}
vecRec.push_back(rect);
if (vecRec.size() == 6){
sort(vecRec.begin(), vecRec.end());
bool bPossible = false;
if (vecRec[0] == vecRec[1] && vecRec[2] == vecRec[3] && vecRec[4] == vecRec[5]){
if (vecRec[0].width == vecRec[2].width &&
vecRec[0].height == vecRec[4].width &&
vecRec[2].height == vecRec[4].height) bPossible = true;
}
if (bPossible) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
vecRec.clear();
}
}
return 0;
}
/*
1345 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
1234 4567
1234 4567
4567 4321
4322 4567
4321 1234
4321 1234
*/