UVA 1587 Box(模拟)

62 篇文章 0 订阅
9 篇文章 0 订阅

题目地址: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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值