UVA-1587 Box

题目在这

题目大意:
多次询问,每次询问给你六组数据,每组数据包括两个数作为矩形的边长,请判断这六组数据能否构成长方体。

我的做法:首先在一组数据中排序,小的作为第一个数,之后每组数据升序排序,排序标准是先按照第一个数升序,再按照第二个数升序。
根据长方体的构成要素,有三组对应面全等,再有长宽高,并且每两个相邻面都必须有一个重合的边。所以如果这六组数据构成长方体,排序之后,每两组数据必须全等,第一组的min等于第二组的min,第一组的max等于第三组的min,第二组的max等于第三组的max。
我的代码是吧这两个条件分开看了,诸位看官也可以合并为一个条件,使代码更精炼。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
#include <vector>
#include <queue>
#include <ctime>
#include <ctype.h>
#define ll long long
//#define local
#define inf 0x3f3f3f3f
using namespace std;
const int N = 1005;
const int mod = 1e9 + 7;
char p[]= {"POSSIBLE\n"};
char ip[]= {"IMPOSSIBLE\n"};
struct node
{
    int a,b;
} c[6];
bool cmp(node x,node y)
{
    if(x.a!=y.a)
        return x.a<y.a;
    else
        return x.b<y.b;
}
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
#endif
    while(scanf("%d%d",&c[0].a,&c[0].b)!=EOF)
    {
        int s=0,t=0;
        for(int i=1; i<6; i++)
            scanf("%d%d",&c[i].a,&c[i].b);
        for(int i=0; i<6; i++)
            if(c[i].a>c[i].b)
                swap(c[i].a,c[i].b);
        sort(c,c+6,cmp);
        if(c[0].a==c[1].a&&c[0].b==c[1].b&&c[2].a==c[3].a&&c[2].b==c[3].b&&c[4].a==c[5].a&&c[4].b==c[5].b)
            s=1;
        int l1=c[0].a,l2=c[0].b;
        int l3=c[2].a,l4=c[2].b;
        int l5=c[4].a,l6=c[4].b;
        if(l1==l3&&l2==l5&&l4==l6)
            t=1;
        if(s*t)
            printf("%s",p);
        else
            printf("%s",ip);

    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值