UVa 1587

这道题思路明确了还是不难的,关键是判断方法。

长方体有三种不同的边,我们记为abc,并且记a>b>c,则长方体的六个面必定是ab、ab、ac、ac、bc、bc(按照边的长度排序),符合这种形式的就是一个长方体。

根据题目叙述,重点是怎样把输入的数据转化为这种标准形式,然后进行判断。

首先把每个面的两条边大小弄清楚,如ba转换为ab,即长>宽;

然后对六个面进行排序,按照长从大到小排序,长相同,按宽排序;

接下来进行判断,长方体含有“三对”面,并且一对面中的长或宽等于另一对面中的长或宽,符合条件的即为长方体。

#include <bits/stdc++.h>
using namespace std;

struct face{
    int x, y;
}a[6];
bool check()
{
    if(memcmp(a, a+1, sizeof(face)) || memcmp(a+2, a+3, sizeof(face)) || memcmp(a+4, a+5, sizeof(face))) return false;
    if(a[0].x!=a[2].x || a[0].y!= a[4].x || a[2].y!=a[4].y) return false;
    return true;
}
int main()
{
    while(cin >> a[0].x >> a[0].y >> a[1].x >> a[1].y >> a[2].x >> a[2].y >> a[3].x >> a[3].y >> a[4].x >> a[4].y >> a[5].x >> a[5].y){
        for(int i = 0; i < 6; ++i)
            if(a[i].x < a[i].y)
                swap(a[i].x, a[i].y);
        sort(a, a+6, [](const face a, const face b) {return a.x==b.x ? (a.y > b.y) : (a.x > b.x);});
        printf("%s
", check() ? "POSSIBLE" : "IMPOSSIBLE");
    }
    return 0;
}




原文地址:https://www.cnblogs.com/kunsoft/p/5312721.html