UVa 1587-box

Source: Internet
Author: User


The idea of this problem is clear or not difficult, the key is to judge the method.



Cuboid has three different sides, we remember as ABC, and remember A>b>c, then the cuboid of the six faces must be AB, AB, AC, AC, BC, BC (according to the length of the order), in line with this form is a cuboid.



According to the topic, the emphasis is on how to convert the input data into this standard form and then make a judgment.



First, the size of each side of the two edge to figure out, such as BA conversion to AB, that is, long > wide;



Then the six faces are sorted, sorted by length from big to small, the same length, sorted by width;



Next to judge, the cuboid contains a "three-pair" face, and the length or width of the opposite is equal to the length or width of another pair of faces, the condition is cuboid.





#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\n", check() ? "POSSIBLE" : "IMPOSSIBLE");
    }
    return 0;
}











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.