UVA 1587 Box (IDEA)

Source: Internet
Author: User

Give the length and width (or width and length) of the 6 rectangles, and ask whether the six rectangles can form a box.

The idea is relatively simple, but there are a lot of places to pay attention to.

First, because of the length and width of the order, so to deal with (at first only to deal with the later reading of the five groups, no processing of the first group read separately, bad reviews)

Then decide if you can divide into 22 identical three groups.

If able, enumerate 8 possible equal cases.

1 /*************************************************************************2 > File name:code/uva/1587.cpp3 > Author:111qqz4 > Email: [Email protected]5 > Created time:2015 September 22 Tuesday 12:20 58 seconds6  ************************************************************************/7 8#include <iostream>9#include <iomanip>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <map> -#include <Set> -#include <queue> -#include <vector> +#include <stack> -#include <cctype> + #defineY1 HUST111QQZ A #defineYn hez111qqz at #defineJ1 CUTE111QQZ - #defineMS (A,X) memset (A,x,sizeof (a)) - #defineLR DYING111QQZ - using namespacestd; - #definefor (i, n) for (int i=0;i<int (n); ++i) -typedefLong LongLL; intypedefDoubleDB; - Const intINF =0x3f3f3f3f; to  + structQ - { the     intw,h; *}a,b,c,q[Ten]; $ BOOLOk (inti)Panax Notoginseng { -      the     if(q[i].w==q[i+1].w&&q[i].h==q[i+1].H)return true; +     return false; A } the  + BOOLSolve () - { $     if(A.W==B.W&AMP;&AMP;A.H==C.H&AMP;&AMP;B.H==C.W)return true; $     if(A.W==B.H&AMP;&AMP;A.H==C.H&AMP;&AMP;B.W==C.W)return true; -     if(a.w==b.w&&a.h==c.w&&b.h==c.h)return true; -     if(a.w==b.h&&a.h==c.w&&b.w==c.h)return true; the  -     if(a.w==c.w&&a.h==b.h&&b.w==c.h)return true;Wuyi     if(a.w==c.w&&a.h==b.w&&b.h==c.h)return true; the     if(A.W==C.H&AMP;&AMP;A.H==B.W&AMP;&AMP;B.H==C.W)return true; -     if(A.W==C.H&AMP;&AMP;A.H==B.H&AMP;&AMP;B.W==C.W)return true; Wu     return false; - } About  $ BOOLCMP (Q a,q B) - { -     if(A.W&LT;B.W)return true; -     if(a.w==b.w&&a.h<b.h)return true; A     return false; + } the intMain () - { $ #ifndef Online_judge theFreopen ("In.txt","R", stdin); the   #endif the  the     while(SCANF ("%d%d", &q[0].w,&q[0].H)! =EOF) -     { in     if(q[0].w>q[0].h) Swap (q[0].w,q[0].h); the      for(inti =1; I <6; i++) the     { About        //scanf ("%d%d", &w[i],&h[i]); //It's stupid. began to open two arrays of read length and width. After sorting, the correspondence will disrupt the 233. thescanf"%d%d",&q[i].w,&q[i].h); the         if(q[i].w>q[i].h) Swap (q[i].w,q[i].h); the     } +      -     BOOLFlag =true; theSort (q,q+6, CMP);Bayi //for (int i = 0; i < 6; i++) cout<<q[i].w<< "" <<q[i].h<<endl; the      for(inti =0; I <6; i = i +2) the     { -         if(!OK (i)) -         { theFlag =false; the          Break; the         } the     } -     if(!flag) the     { thePuts"Impossible"); the         Continue;94     } theA.W = q[0].W; a.h=q[0].h; theB.W = q[2].W; b.h=q[2].h; theC.W = q[4].W; c.h=q[4].h;98 //cout<<a.w<< "" <<a.h<<endl; About //cout<<b.w<< "" <<b.h<<endl; - //cout<<c.w<< "" <<c.h<<endl;101 102     if(Solve ())103     {104Puts"POSSIBLE"); the     }106     Else107     {108Puts"Impossible");109     } the 111     } the   113     the #ifndef Online_judge the fclose (stdin); the   #endif117     return 0;118}
View Code

UVA 1587 Box (IDEA)

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.