BoxTime
limit:MS
Memory Limit:0KB
64bit IO Format:%lld & %llu SubmitStatus
Description
Ivan works at a factory, that produces heavy machinery. He has a simple job--he knocks up wooden boxes of different sizes to pack machinery for delivery to the customers. Each box is a rectangular parallelepiped. Ivan uses six rectangular wooden pallets to make a box. Each pallet are used for one side of the box. Joe delivers pallets for Ivan. Joe isn't very smart and often makes mistakes--he brings Ivan pallets that does not fit together into make a box. But Joe does is not trust Ivan. It always takes a lot of time to explain Joe the He has made a mistake. Fortunately, Joe adores everything related to computers and sincerely believes the computers never make mistakes. Ivan has decided-use the this for his own advantage. Ivan asks you to write a program that given sizes of six rectangular pallets tells whether it's possible to make a box ou T of them.InputInput file contains several test cases. Each of them consists of six lines. Each line describes one pallet and contains the integer numbers
Wand
h(1
w,
HTen)--width and height of the pallet in millimeters respectively.OutputFor each test case, print one output line. Write a single word 'POSSIBLE' To the output file if it's possible to make a box using six given pallets for its sides. Write a single word 'Impossible' If it is not a possible to does so.Sample Input
1345 25842584 6832584 1345683 1345683 13452584 6831234 45671234 45674567 43214322 45674321 12344321 1234
Sample Output
Possibleimpossible
Test instructions: Gives the length and width of six rectangles, judging whether they can form the six faces of a cuboid.
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <queue > #include <set> #include <stack> #include <algorithm> #include <cstdlib> #define MAXN 20using namespace std;struct node{int x, y;} St[maxn];int CMP (Node A,node b) {if (a.x==b.x) return a.y<b.y; return a.x<b.x;} int main () {int a A, B; while (~SCANF ("%d", &a)) {int flag=1; scanf ("%d", &b); if (a>b) swap (A, b); St[0].x=a,st[0].y=b; for (int i=1;i<6;i++) {scanf ("%d%d", &a,&b); if (a>b) swap (A, b); Put the smaller side on the front st[i].x=a; St[i].y=b; } sort (st,st+6,cmp); Sort for (int i=0;i<6;i+=2) {if (!) ( ST[I].X==ST[I+1].X&&ST[I].Y==ST[I+1].Y)//If the X and Y inequalities of each of the two adjacent faces must not meet {flag=0; Break }} if (flag) {if (st[0].x!=st[2].x)//The smallest two edges of different faces cannot coincide with the flag=0; if (! ( (ST[0].Y==ST[4].X&&ST[2].Y==ST[4].Y) | | (st[0].y==st[4].y&&st[2].y==st[4].x))) Determine whether the third surface can be flag=0 with the first two faces; } if (flag) printf ("possible\n"); else printf ("impossible\n"); } return 0;}
Box UVa 1587