UVa_1587 - Box

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.

\epsfbox{p3214.eps}

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 (1$ \le$w,h$ \le$10 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;
}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值