Uva1587

Box UVA - 1587

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 numbers w and h (1 ≤ w,h ≤ 10000) — 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

 1 #include<bits/stdc++.h>
 2 #define maxn 100010
 3 using namespace std;
 4 int main()
 5 {
 6     int w[6],h[6];
 7     while(cin>>w[0]>>h[0]>>w[1]>>h[1]>>w[2]>>h[2]>>w[3]>>h[3]>>w[4]>>h[4]>>w[5]>>h[5])
 8     {
 9         set<int>a;
10         for(int i=0;i<6;i++)
11         {
12             a.insert(w[i]);
13             a.insert(h[i]);
14         }
15         int len=a.size();
16         if(len==1)printf("POSSIBLE\n");
17         else if(len==2)
18         {
19             int sum=0;
20             for(int i=0;i<=5;i++)
21             {
22                 if(w[i]==h[i])
23                 {
24                     sum++;
25                 }
26             }
27             if(sum==2)printf("POSSIBLE\n");
28             else printf("IMPOSSIBLE\n");
29         }
30         else if(len==3)
31         {
32             int flag=0;
33             int k[3],j=0;
34             for(set<int>::iterator it=a.begin();it!=a.end();it++)
35             {
36                 k[j++]=*it;
37             }
38             int k1=0,j1=0,l1=0;
39             for(int i=0;i<=5;i++)
40             {
41                 if(w[i]==h[i])
42                 {
43                     flag=1;break;
44                 }
45                 if(k[0]==w[i]||k[0]==h[i])k1++;
46                 if(k[1]==w[i]||k[1]==h[i])j1++;
47                 if(k[2]==w[i]||k[2]==h[i])l1++;
48             }
49             if(k1!=4||j1!=4||l1!=4)flag=1;
50             if(!flag)printf("POSSIBLE\n");
51             else printf("IMPOSSIBLE\n");
52         }
53         else
54             printf("IMPOSSIBLE\n");
55     }
56     return 0;
57 }

思路:

判断输入进的每组数中有几个不同的值。

1个值 必定成立。

2个值 如果出现两次w[i]==h[i]成立否则不成立。

3个值 必须保证每个值出现4次且h[i]!=w[i],第一次做WA就在这里,没有考率到 4 5 ,4 5, 3 4,3 4,3 4,3 5这样的错误情况,只考虑了h[i]!=w[i]。

4个值及以上必定不成立。

转载于:https://www.cnblogs.com/zuiaimiusi/p/10941203.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值