Test instructions: Gives the length and width of 6 rectangles, asks if it can form a cuboid
Let's first assume an example
2 3
3 4
2 3
3 4
4 2
4 2
After sorting
2 3
2 3
3 4
3 4
4 2
4 2
If you want to form a box, there are 3 opposite is the same as the first to judge this set up, and then determine whether to form a cuboid hypothesis now the rest of the surface is
2 3 (first face)
3 4 (second face)
4 2 (third side)
The discovery is the end-to-end, that is, only need to judge three times, the first face of the long or wide or both in the second surface, the first face of the long or wide or both in the third surface, the second face of the long or wide or both in the third surface, if the three conditions are satisfied, constitutes a
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7 structnode8 {9 intx, y;Ten} a[Ten]; One A intCMP (node n1,node n2) - { - if(n1.x!=n2.x) the returnn1.x<n2.x; - Else returnn1.y<n2.y; - } - + intMain () - { + intI,j,ans; A while(SCANF ("%d", &a[1].x)! =EOF) at { -scanf"%d", &a[1].y); - for(i=2; i<=6; i++) -scanf"%d%d",&a[i].x,&a[i].y); - - for(i=1; i<=6; i++) in { - if(a[i].x>a[i].y) Swap (A[I].X,A[I].Y); to } +Sort (A +1, A +6+1, CMP); - the //For (i=1;i<=6;i++) * //printf ("%d%d\n", a[i].x,a[i].y); $ Panax Notoginsengans=0; - intflag=1; the if(a[1].x==a[2].x&&a[1].y==a[2].y&&a[3].x==a[4].x&&a[3].y==a[4].y&&a[5].x==a[6].x&&a[5].y==a[6].y) + { A if(a[1].x==a[3].x| | a[1].x==a[3].y| | a[1].y==a[3].x| | a[1].y==a[3].Y) ans++; the if(a[1].x==a[5].x| | a[1].x==a[5].y| | a[1].y==a[5].x| | a[1].y==a[5].Y) ans++; + if(a[3].x==a[5].x| | a[3].x==a[5].y| | a[3].y==a[5].x| | a[3].y==a[5].Y) ans++; - if(ans<3) flag=0; $ $ } - Else -flag=0; the - if(flag) printf ("possible\n");Wuyi Elseprintf"impossible\n"); the } - return 0; Wu}View Code
But then I thought of a counter-example = I was thinking of changing the time---actually over = = = Counter example is
12 34
34 12
12 34
34 12
12 34
12 34
This should not constitute--but the program output is able to----do not understand =
UVa 1587 Box