(UVA)1587Box

来源:互联网 发布:帝国坟场 阿富汗 知乎 编辑:程序博客网 时间:2024/06/05 16:36

给定六个面判断能否构成一个长方体;搞清面与面之间的关系即可;

#include <cstdio>#include <algorithm>using namespace std;struct Rec{    int w,h;    Rec(){}    Rec(int ww,int hh):w(ww),h(hh){}    bool operator<(const Rec &other)const{        if(w==other.w)return h<other.h;        return w<other.w;    }    bool operator==(const Rec &other)const{        if(w==other.w&&h==other.h)return true;        return false;    }}rec[6];bool ok(){    for(int i=0;i<3;i++)        if(rec[2*i]==rec[2*i+1])continue;        else return false;    if(rec[0].h==rec[2].h&&rec[0].w==rec[4].h&&rec[2].w==rec[4].w)return true;    return false;}int main(){    while(scanf("%d%d",&rec[0].w,&rec[0].h)!=EOF){        for(int i=1;i<6;i++)scanf("%d%d",&rec[i].w,&rec[i].h);        for(int i=0;i<6;i++)if(rec[i].h>rec[i].w)swap(rec[i].w,rec[i].h);        sort(rec,rec+6);        if(ok())printf("POSSIBLE\n");        else printf("IMPOSSIBLE\n");    }}


0 0