Problem 019 —— UVa 1587 - Box

Ivan works at a factory that produces heavy machinery. He hasa simple job -- he knocks up wooden 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 numbers w 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



#include"cstdio"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include <algorithm>
using namespace std;

int box[6][2];
int x[3][2];
int pd[6];

int main()
{
    while(cin >> box[0][0] >> box[0][1]){
        for(int i=1;i<6;i++)
            cin >> box[i][0] >> box[i][1];
        for(int i=0;i<6;i++){
            if(box[i][0]>box[i][1]){
                int t=box[i][0];
                box[i][0]=box[i][1];
                box[i][1]=t;
            }
        }
        int k=0;
        memset(x,0,sizeof(x));
        for(int i=0;i<5;i++)
            for(int j=i+1;j<6;j++){
                if(box[i][0]==box[j][0]&&box[i][1]==box[j][1]&&box[i][0]){
                    x[k][0]=box[i][0],x[k++][1]=box[i][1];
                    box[j][0]=box[j][1]=box[i][1]=box[i][0]=0;
                }
            }
        k=0;
        memset(pd,0,sizeof(pd));
        for(int i=0;i<3;i++)
            for(int j=0;j<2;j++)
                pd[k++]=x[i][j];
        sort(pd,pd+6);
        if(pd[0]==0)
            printf("IMPOSSIBLE\n");
        else if(pd[0]==pd[1]&&pd[2]==pd[3]&&pd[4]==pd[5])
            printf("POSSIBLE\n");
        else
            printf("IMPOSSIBLE\n");
        memset(box,0,sizeof(box));
    }
    return 0;
}





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值