UVA - 1587 Box :锻炼了我的模拟能力



思路:算是找规律吧

按照一定规则重新排列六个面 详情见代码 比如 样例一


初始状态
1345 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
排列后状态
683 1345
683 1345
683 2584
683 2584
1345 2584
1345 2584
首先比较前两个面 如果相等 则判断接下来的四个面是否有共同的高 如果有 再判断 其余四个面是否与已确定的两个面具有共同的长和宽


                //#define LOCAL

#include <map>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

struct Node{
    int l;
    int w;

};

bool Cmp( const Node &a, const Node &b ){
    if(a.w==b.w) return a.l<b.l;
    return a.w<b.w;
}

int main()
{
#ifdef LOCAL
    freopen("in1.txt","r",stdin);
#endif

    int brk;
    Node node;
    vector<Node>vec;
    while(~scanf("%d %d",&node.w,&node.l)){
        brk=0;
        vec.clear();

        if(node.w>node.l) swap(node.w,node.l);
        vec.push_back(node);
        for(int i=0; i<5; i++){
            scanf("%d %d",&node.w,&node.l);
            if(node.w>node.l) swap(node.w,node.l);
            vec.push_back(node);
        }

        sort(vec.begin(),vec.end(),Cmp);
//        for(int i=0; i<6; i++){
//            cout<<vec[i].w<<" "<<vec[i].l<<endl;
//        }
        if(vec[0].w!=vec[1].w || vec[0].l!=vec[1].l){
            brk=1;
        }
        else{
            if( vec[2].l!=vec[3].l || vec[2].l!=vec[4].l || vec[2].l!=vec[5].l ) brk=1;
            else{
                if (vec[2].w!=vec[0].w || vec[3].w!=vec[0].w) brk=1;
                if (vec[4].w!=vec[0].l || vec[5].w!=vec[0].l) brk=1;
            }
        }

        if(brk) 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、付费专栏及课程。

余额充值