思路:一个长方形六个面之间两两相等,所以在确认了六个面两两相等之后,只需要通过3个面就可以确定是否能形成一个长方形,通过按升序排好的长方体进行优化就可以找到规律来。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef struct node{
int h,w;
}nod;
nod node[7];
bool map(nod x,nod y)
{
if(x.w!=y.w)
return x.w<y.w;
else return x.h<y.h;
}
bool fun()
{
if(node[1].w!=node[2].w||node[1].h!=node[2].h)return false;
else if(node[3].w!=node[4].w||node[3].h!=node[4].h)return false;
else if(node[5].w!=node[6].w||node[5].h!=node[6].h)return false;
else if(node[1].w!=node[3].w||node[5].w!=node[1].h||node[3].h!=node[5].h) return false;
else return true;
}
int main()
{
int x,y;
while(1)
{
for(int i=1;i<=6;i++)
{
if(scanf("%d%d",&x,&y)!=2)return 0;
if(x>y){node[i].h=x;node[i].w=y;
}else {node[i].h=y;node[i].w=x;
}
}
sort(node+1,node+7,map);
bool f=fun();
if(f)printf("POSSIBLE\n");
else printf("IMPOSSIBLE\n");
}
return 0;
}