uva 1587 Box(思路)

给6个矩形的长和宽(或者宽和长),问这六个矩形能否组成一个长方体.

思路比较简单,不过需要注意的地方有点多.

首先由于长和宽的顺序为止,所以要处理一下(一开始只处理了后来读入的五组,没有处理单独读入的第一组,差评)

然后要判断能否分成两两相同的三组.

如果能,枚举8种可能的相等的情况.

  1/*************************************************************************
  2	> File Name: code/uva/1587.cpp
  3	> Author: 111qqz
  4	> Email: rkz2013@126.com 
  5	> Created Time: 2015年09月22日 星期二 12时20分58秒
  6 ************************************************************************/
  7#include<iostream>
  8#include<iomanip>
  9#include<cstdio>
 10#include<algorithm>
 11#include<cmath>
 12#include<cstring>
 13#include<string>
 14#include<map>
 15#include<set>
 16#include<queue>
 17#include<vector>
 18#include<stack>
 19#include<cctype>
 20#define y1 hust111qqz
 21#define yn hez111qqz
 22#define j1 cute111qqz
 23#define ms(a,x) memset(a,x,sizeof(a))
 24#define lr dying111qqz
 25using namespace std;
 26#define For(i, n) for (int i=0;i<int(n);++i)  
 27typedef long long LL;
 28typedef double DB;
 29const int inf = 0x3f3f3f3f;
 30struct Q
 31{
 32    int w,h;
 33}a,b,c,q[10];
 34bool ok ( int i)
 35{
 36    if (q[i].w==q[i+1].w&&q[i].h==q[i+1].h) return true;
 37    return false;
 38}
 39bool solve ()
 40{
 41    if (a.w==b.w&&a.h==c.h&&b.h==c.w) return true;
 42    if (a.w==b.h&&a.h==c.h&&b.w==c.w) return true;
 43    if (a.w==b.w&&a.h==c.w&&b.h==c.h) return true;
 44    if (a.w==b.h&&a.h==c.w&&b.w==c.h) return true;
 45    if (a.w==c.w&&a.h==b.h&&b.w==c.h) return true;
 46    if (a.w==c.w&&a.h==b.w&&b.h==c.h) return true;
 47    if (a.w==c.h&&a.h==b.w&&b.h==c.w) return true;
 48    if (a.w==c.h&&a.h==b.h&&b.w==c.w) return true;
 49    return false;
 50}
 51bool cmp(Q a,Q b)
 52{
 53    if (a.w<b.w) return true;
 54    if (a.w==b.w&&a.h<b.h) return true;
 55    return false;
 56}
 57int main()
 58{
 59  #ifndef  ONLINE_JUDGE 
 60   freopen("in.txt","r",stdin);
 61  #endif
 62   while (scanf("%d %d",&q[0].w,&q[0].h)!=EOF)
 63    {
 64	if (q[0].w>q[0].h) swap(q[0].w,q[0].h);
 65	for ( int i = 1 ; i < 6 ; i++)
 66	{
 67	   // scanf("%d %d",&w[i],&h[i]);           //蠢了..开始开了两个数组读的长和宽.排序后对应关系就打乱了233
 68	    scanf("%d %d",&q[i].w,&q[i].h);
 69	    if (q[i].w>q[i].h) swap(q[i].w,q[i].h);
 70	}
 71	bool flag = true;
 72	sort(q,q+6,cmp);
 73//	for ( int i = 0 ; i < 6 ; i++) cout<<q[i].w<<" "<<q[i].h<<endl;
 74	for ( int i = 0 ; i < 6 ; i = i + 2)
 75	{
 76	    if (!ok(i))
 77	    {
 78		flag = false;
 79		break;
 80	    }
 81	}
 82	if (!flag)
 83	{
 84	    puts("IMPOSSIBLE");
 85	    continue;
 86	}
 87	a.w = q[0].w; a.h=q[0].h;
 88	b.w = q[2].w; b.h=q[2].h;
 89	c.w = q[4].w; c.h=q[4].h;
 90//	cout<<a.w<<" "<<a.h<<endl;
 91//	cout<<b.w<<" "<<b.h<<endl;
 92//	cout<<c.w<<" "<<c.h<<endl;
 93	if (solve())
 94	{
 95	    puts("POSSIBLE");
 96	}
 97	else
 98	{
 99	    puts("IMPOSSIBLE");
100	}
101    }
102 #ifndef ONLINE_JUDGE  
103  fclose(stdin);
104  #endif
105	return 0;
106}