ooden boxes of different sizesto pack machinery for delivery to the customers. Each boxis a rectangular parallelepiped. Ivan uses six rectangular wooden palletsto make a box. Each pallet is used for one side of the box.
Joe delivers pallets for Ivan. Joe is not very smart andoften makes mistakes -- he brings Ivan pallets that do not fittogether to make a box. But Joe does not trust Ivan. It alwaystakes a lot of time to explain Joe that he has made a mistake.Fortunately, Joe adores everything related to computers and sincerelybelieves that computers never make mistakes. Ivan has decided touse this for his own advantage. Ivan asks you to writea program that given sizes of six rectangular palletstells whether it is possible to make a box out of them.
Input
Input file contains several test cases. Each of them consists of six lines. Each line describes one pallet andcontains two integer numbersw and h (1w,h10 000) --width and height of the pallet in millimeters respectively.
Output
For each test case, print one output line. Write a single word `POSSIBLE' to the output file if it is possibleto make a box using six given pallets for its sides. Write a single word`IMPOSSIBLE' if it is not possible to do so.
Sample Input
1345 2584 2584 683 2584 1345 683 1345 683 1345 2584 683 1234 4567 1234 4567 4567 4321 4322 4567 4321 1234 4321 1234
Sample Output
POSSIBLE IMPOSSIBLE
题意:
给定6对面的长和宽,判定是否可以组成长方体
解题:
1. 设长方体的长,宽,高分别为a,b,c(a<=b<=c),那么满足以下条件的话,就是长方体;
a b
a b
a c
a c
b c
b c
2. 本题的思路就是首先排序,对于6行2列的数据,保证横竖都从小到大,然后判定是否满足上述的长方体的格式即可
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
int h,w;
bool operator < (const node& r) const { return h<r.h || h==r.h&&w<r.w; }
}r[7];
bool read()
{
memset(r,0,sizeof(r));
while(cin>>r[0].h>>r[0].w)
{
if(r[0].h>r[0].w) swap(r[0].h,r[0].w);
for(int i=1;i<6;i++) { cin>>r[i].h>>r[i].w; if(r[i].h>r[i].w) swap(r[i].h,r[i].w);}
return true;
}
return false;
}
bool Is_box()
{
if(r[0].h!=r[1].h || r[0].w!=r[1].w) return false;
if(r[2].h!=r[3].h || r[2].w!=r[3].w) return false;
if(r[4].h!=r[5].h || r[4].w!=r[5].w) return false;
if(r[0].h!=r[2].h) return false;
if(r[0].w!=r[4].h) return false;
if(r[2].w!=r[4].w) return false;
return true;
}
int main()
{
//freopen("1587.txt","r",stdin);
while(read())
{
sort(r,r+6);
if(Is_box()) cout<<"POSSIBLE"<<endl;
else cout<<"IMPOSSIBLE"<<endl;
}
return 0;
}