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

UVa1587

时间:2016-08-14 20:36:05      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

1587 Box
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 t 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 le contains several test cases. Each of them consists of six lines. Each line describes one pallet
and contains two integer numbers w and h (1  w; h  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 le 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
Universidad de Valladolid OJ: 1587 { Box 2/2
Sample Output
POSSIBLE
IMPOSSIBLE

技术分享

题意:

       给出六个长方形的长和宽,判断它们是否能够构成一个长方体。

 

输入:

       多组数据,每组6行,每行两个整数表示长和宽。

输出:

       每组一行,输出判断结果。

 

分析:

       使用pair来表示长方形,first量表示长,second量表示宽。输入数据后,对6个长方形进行排序first量小的排在前面的情况下second量小的排在前面。如果能够组成长方体,那么这6个长方形能够分成三组,每组两个相同的长方形。此外,三组长方形的边长应该分别满足:a,b;b,c;c,a。为了方便,我们在输入的时候就让每一个矩形pair的first量总小于second量。不妨设a<b<c,如果输入的6个矩形可以组成一个长方体,那么排序后位于前面的两个矩形的first和second量分别为a和b,中间的两个矩形为a和c,最末的两个矩形为b和c,反之也成立。

 

技术分享
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 typedef pair<int,int> P;
 8 bool cmp(const P& p1,const P& p2){
 9     if(p1.first < p2.first) return true;
10     if(p1.first == p2.first) return p1.second < p2.second;
11     return false;
12 }
13 P p[10];
14 int main(){
15     int a,b;
16     while(scanf("%d%d",&a,&b) != EOF){
17         if(a > b){
18             int tmp = a;
19             a = b; b = tmp;
20         }
21         p[0].first = a; p[0].second = b;
22         for(int i = 1; i < 6 ; i++){
23             scanf("%d%d",&p[i].first,&p[i].second);
24             if(p[i].first > p[i].second){
25                 int tmp = p[i].first;
26                 p[i].first = p[i].second;
27                 p[i].second = tmp;
28             }
29         }
30         sort(p,p + 6,cmp);
31         //for(int i = 0 ;i < 6 ; i++)
32         //    cout << p[i].first <<  " " << p[i].second << endl;
33         if(p[0].first == p[1].first && p[0].second == p[1].second
34            && p[2].first == p[3].first && p[2].second == p[3].second
35            && p[4].first == p[5].first && p[4].second == p[5].second){
36             int x = p[0].first,y = p[2].second,z = p[0].second;
37             int x1 = p[2].first,y1 = p[4].second,z1 = p[4].first;
38             //int y2 = p[4].second,z2 = p[4].first;
39             //printf("%d %d %d\n",x,y,z);
40             //printf("%d %d %d\n",x1,y1,z1);
41             if(x == x1 && y == y1 && z == z1) {
42                 printf("POSSIBLE\n");
43                 continue;
44             }
45             else{
46                 printf("IMPOSSIBLE\n");
47                 continue;
48             }
49         }
50         else printf("IMPOSSIBLE\n");
51     }
52     return 0;
53 }
View Code

 

UVa1587

标签:

原文地址:http://www.cnblogs.com/cyb123456/p/5770821.html

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