UVA 1587 Box

来源:互联网 发布:如何查看淘宝交易快照 编辑:程序博客网 时间:2024/06/16 06:21

题意:给出六个矩形的长度,问是否可以组成一个长方体.

思路:长方体的长方形格式是定下来的,所以说我们用pair<int,int>来存下来每一个长方形,pair第一个关键字存长然后第二关键字存宽,长比宽大,如果不行的话自动调换位置.然后自带sort将它排序好.

    满足以下条件之一将不为长方体.

    1.第一个和第二个pair或者第三个和第四个pair或者第五个和第六个pair不相等

    2.第一个pair的长不等于第五个pair的宽或者第一个pair的宽不和第三个pair的宽相等或者第三个pair的宽不和第五个的宽相等.

看代码:

#ifdef POJ   #include <iostream>   #include <cstdio>   #include <cstdlib>   #include <cstring>   #include <cmath>   #include <algorithm>   #include <set>   #include <vector>   #include <map>   #include <queue>   #include <stack>#else   #include <bits/stdc++.h>#endif#define ll long long#define db double#define pb push_backusing namespace std;pair<int,int> p[6];bool ok(){    if (p[0]!=p[1]||p[2]!=p[3]||p[4]!=p[5]) return false;    if (p[0].first!=p[4].second||p[0].second!=p[2].second||p[2].first!=p[4].first) return false;    return true;}int main(){   #ifdef LOCAL      freopen("in.txt","r",stdin);      freopen("out.txt","w",stdout);   #endif   while (scanf("%d%d",&p[0].first,&p[0].second)==2)   {       if (p[0].first<p[0].second) swap(p[0].first,p[0].second);       for (int i=1;i<6;i++)       {         scanf("%d%d",&p[i].first,&p[i].second);         if (p[i].first<p[i].second) swap(p[i].first,p[i].second);       }       sort(p,p+6);       if (ok()) puts("POSSIBLE");       else puts("IMPOSSIBLE");   }   return 0;}


0 0
原创粉丝点击