码迷,mamicode.com
首页 > 其他好文 > 详细

uva1587 Box

时间:2015-01-05 18:39:29      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

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 is used for one side of the box.

技术分享

Joe delivers pallets for Ivan. Joe is not very smart and often makes mistakes -- he brings Ivan pallets that do not fit together to make a box. But Joe does not trust Ivan. It always takes a lot of time to explain Joe that he has made a mistake. Fortunately, Joe adores everything related to computers and sincerely believes that computers never make mistakes. Ivan has decided to use this for his own advantage. Ivan asks you to write a program that given sizes of six rectangular pallets tells whether it is possible to make a box out of them.

Input 

Input file contains several test cases. Each of them consists of six lines. Each line describes one pallet and contains two integer numbersw and h ( 1技术分享wh技术分享10 000) -- width and height of the pallet in millimeters respectively.

Output 

For each test case, print one output line. Write a single word ` POSSIBLE‘ to the output file if it is possible to make a box using six given pallets for its sides. Write a single word ` IMPOSSIBLE‘ if it is not possible to do so.

Sample Input 

1345 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
1234 4567
1234 4567
4567 4321
4322 4567
4321 1234
4321 1234

Sample Output 

POSSIBLE
IMPOSSIBLE

希望每次代码都有进步。
AC代码:
技术分享
 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 
 6 struct Box
 7 {
 8     int a,b;
 9 } box[6];
10 
11 
12 void Swap(int *,int *);
13 void Sort();
14 int Judge();
15 
16 
17 int main()
18 {
19     while(cin >> box[0].a >> box[0].b)
20     {
21         if(box[0].a<box[0].b)
22             Swap(&box[0].a,&box[0].b);
23         for(int i=1; i<6; i++)
24         {
25             cin >> box[i].a >> box[i].b;
26             if(box[i].a<box[i].b)
27                 Swap(&box[i].a,&box[i].b);
28         }
29         Sort();
30         if(Judge())
31             cout << "POSSIBLE" << endl;
32         else
33             cout << "IMPOSSIBLE" << endl;
34     }
35     return 0;
36 }
37 void Swap(int *p,int *q)
38 {
39     int r;
40     r=*p;
41     *p=*q;
42     *q=r;
43 }
44 
45 void Sort()
46 {
47     struct Box c;
48     for(int i=1; i<6; i++)
49         for(int j=0; j<6-i; j++)
50         {
51             if(box[j].a<box[j+1].a)
52             {
53                 c=box[j];
54                 box[j]=box[j+1];
55                 box[j+1]=c;
56             }
57         }
58     for(int i=1; i<6; i++)
59         for(int j=0; j<6-i; j++)
60         {
61             if(box[j].b<box[j+1].b&&box[j].a==box[j+1].a)
62             {
63                 c=box[j];
64                 box[j]=box[j+1];
65                 box[j+1]=c;
66             }
67         }
68 }
69 
70 int Judge()
71 {
72     if(box[0].a==box[1].a&&box[1].a==box[2].a&&box[2].a==box[3].a)
73         if(box[0].b==box[1].b&&box[1].b==box[4].a&&box[4].a==box[5].a)
74             if(box[2].b==box[3].b&&box[3].b==box[4].b&&box[4].b==box[5].b)
75                 return 1;
76     return 0;
77 }
View Code

 

uva1587 Box

标签:

原文地址:http://www.cnblogs.com/I-love-HLD/p/4204058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!