题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=448&page=show_problem&problem=4462
思路:分三种面,模拟,注意判断每种面的个数。
#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define debu
using namespace std;
struct Node
{
int x,y;
bool operator == (const Node &rhs) const
{
return x==rhs.x&&y==rhs.y;
}
bool operator < (const Node &rhs) const
{
if(x==rhs.x) return y<rhs.y;
else return x<rhs.x;
}
};
map<Node,int> M;
Node a[10],b[10];
int main()
{
#ifdef debug
freopen("in.in","r",stdin);
#endif // debug
int tot=0,x,y;
while(scanf("%d%d",&x,&y)!=EOF)
{
tot%=6,a[tot]=(Node) {min(x,y),max(x,y)},tot+=1;
if(tot==6)
{
M.clear();
for(int i=0; i<6; i++) M[a[i]]++;
int flag=0;
sort(a,a+6);
int num=unique(a,a+6)-a;
if(num==3)
{
if(M[a[0]]==2&&M[a[1]]==2&&M[a[2]]==2)
{
do
{
if(a[0].x==a[2].x&&a[1].y==a[0].y&&a[2].y==a[1].x)
{
flag=1;
break;
}
}
while(next_permutation(a,a+3));
}
}
else if(num==1)
{
if(a[0].x==a[0].y) flag=1;
}
else if(num==2)
{
if((M[a[0]]==4&&M[a[1]]==2)||(M[a[1]]==2&&M[a[0]]==4))
{
b[0]=a[0],b[1]=a[1],b[2]=a[0];
do
{
if(b[0].x==b[2].x&&b[1].y==b[0].y&&b[2].y==b[1].x)
{
flag=1;
break;
}
}
while(next_permutation(b,b+3));
b[0]=a[0],b[1]=a[1],b[2]=a[1];
do
{
if(b[0].x==b[2].x&&b[1].y==b[0].y&&b[2].y==b[1].x)
{
flag=1;
break;
}
}
while(next_permutation(b,b+3));
}
}
if(!flag) printf("IMPOSSIBLE\n");
else printf("POSSIBLE\n");
}
}
return 0;
}