Box

Ivan works at a factory that produces heavy machinery. He has a simple job — he knocks up wooden
boxes of different sizes to pack machinery for delivery to the customers. Each box is a rectangular
parallelepiped. Ivan uses six rectangular wooden pallets to make a box. Each pallet is used for one side of the box.
在这里插入图片描述
Joe delivers pallets for Ivan. Joe is not very smart and often makes mistakes — he brings Ivan
pallets that do not fit together to make a box. But Joe does not trust Ivan. It always takes a lot of
time to explain Joe that he has made a mistake.
Fortunately, Joe adores everything related to computers and sincerely believes that computers never
make mistakes. Ivan has decided to use this for his own advantage. Ivan asks you to write a program
that given sizes of six rectangular pallets tells 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
and contains two integer numbers w and h (1 ≤ w, h ≤ 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
possible to 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

题目大意:给出六个矩形的长和宽,判断这六个矩形是否能组成一个长方体。

哎,做这个题的时候一头雾水,不知道该怎么写。后来还是参考了别人的代码。QwQ太菜了

我们先想一个比较普通的一个矩形吧:
在这里插入图片描述
可能你想的矩形跟我画的不一样,不过没关系,其实只要转变一下就行,我先按照我的这种讲,之后

会给出不同矩形的答复。

因为不太会画画所以大家凑合一下吧QwQ。

为了方便表示,我给每个矩形都编上了号。

根据长方体的性质我们可以知道,1和2是全等的,3和4是全等的,5和6是全等的。

而且我们可以看到,1的长和5的宽是相同的(我们暂时不考虑正方形的情况,因为正方形是一种特殊的长方形,所以长方形可以满足的话正方形也会满足)

因为1和2是全等的,所以如果1的长和5的宽是相同的,2的长和5也是相同的。

类似的,我们可以发现,3的长和5的长是一样的,1的宽和3的宽是一样的。

好,根据这些已经可以判断是否能组成一个长方体了,但是还有一个问题,这里的编号都是我提前编

好了的,但是题目中给出的矩形不一定就按照我这个给呀,如何去找题目中给出的矩形对应的我的哪

一个编号呢?

其实我们仔细观察上图,可以按照每个举行的长排序,1和2是长最小的,2、3、4、5、6的长都是一

样的,都是最大的,这个时候我们再按照宽排序,那么2、3的宽是比较小的,4、5是比较大的。

因此我们可以把给出的六个矩形按照长排序,长度相同的按照宽排序,得到的顺序就是上图的标号。

好,那么有人可能会问,如果是一个正方体怎么办?如果我想的矩形是这样的怎么办:
在这里插入图片描述

就是我开始画的那个矩形是一个扁平扁平的,而这种是一个瘦高瘦高的,这样怎么办呢?其实不用担

心,只要把这个瘦高的长方体倒过来,其实还是一样的。

因此这个题就可以解决了。

喜闻乐见代码系列:

#include <iostream>
#include <algorithm>

using namespace std;

typedef pair < int , int > PII;//对pair排序的时候会优先对第一个关键字排序,所以直接用pair来储存每个举行了

int a , b;
PII c[10];

bool judge()
{
    if(c[1] == c[2] && c[3] == c[4] && c[5] == c[6])
    {
        if(c[1].first == c[5].second && c[1].second == c[3].second && c[3].first == c[5].first)
        {
            return true;
        }
        else return false;
    }
    
    else return false;
}

int main(void)
{
    while(scanf("%d %d",&a , &b) != EOF)
    {
        if(a < b) swap(a , b);
        c[1] = {a , b};
        
        for(int i = 2 ; i <= 6 ; ++ i)
        {
            scanf("%d %d",&a , &b);
            
            if(a < b) swap(a , b);
            
            c[i] = {a , b};
        }
        
        sort(c + 1 , c + 7);
        
        if(judge()) printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值