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 ≤ 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
HINT
题目的意思是给我们六个矩形的长和宽,让我们判断能否构成一个长方体。考虑长方形的特点可知,总会有两个面的长和宽hi相等的,同时12个边中总会又出现至少每4个边是相等的。可以根据这两个条件来判断输入样例。
Accepted
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void* a, const void* b)
{
return *(int*)a - *(int*)b;
}
int main()
{
int a, b;
while (scanf("%d %d", &a, &b) != EOF)
{
int arr[12] = { 0 };
int arr2[6][2] = { 0 };
arr2[0][0] = a > b ? a : b;
arr2[0][1] = a > b ? b : a;
int j = 2;
arr[0] = a;arr[1] = b;
for (int i = 1;i < 6;i++)
{
scanf("%d %d", &a, &b);
arr2[i][0] = a > b ? a : b;
arr2[i][1] = a > b ? b : a;
arr[j++] = a;arr[j++] = b;
}
qsort(arr, 12, sizeof(int), cmp);
int flag = 0;
for (int i = 0;i < 12;i += 4)
for (int j = 0;j < 4;j++)
if (arr[i] != arr[j + i])
flag = 1;
if (!flag)
{
for (int i = 0;i < 6;i++)
{
int j;
if (!arr2[i][0])continue;
for (j = 0;j < 6;j++)
if (i != j && arr2[i][0] == arr2[j][0] && arr2[i][1] == arr2[j][1])
{
arr2[i][0] = arr2[j][0] = arr2[i][1] = arr2[j][1] = 0;
break;
}
if (j == 6)
{
flag = 1;
break;
}
}
}
printf("%s\n", flag == 0 ? "POSSIBLE" : "IMPOSSIBLE");
}
}
Box UVA - 1587的更多相关文章
- uva 1587(Box UVA - 1587)
题目大意是给定6个数对,每个数对代表一个面的长和宽,判断这6个面是否能构成一个长方体. 这种题一看很复杂,但是只要不想多了实际上这就是一个水题... 首先说明一下判断的思路: 1.长方体是有三个对面的 ...
- UVa 1587 Box
题意:给出6个矩形的长和宽,问是否能够构成一个长方体 先假设一个例子 2 3 3 4 2 3 3 4 4 2 4 2 排序后 2 3 2 3 3 4 3 4 4 2 4 2 如果要构成一个长方体的话, ...
- 【每日一题】 UVA - 1587 Box 二维有点偏序的感觉
一开始用set存xjb分类讨论,然后wa, 然后简化了一点,改用vector,然wa 最后又发现没有初始化,然wa wa了一个半小时 最后看了题解orz 然后找了一组样例把自己的代码改对了 /* 1 ...
- 【习题 3-10 UVA - 1587】Box
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举某个顶角的三个相邻面就好. 看看这三个相邻面有没有对应的面. 以及3个相邻面的6个边. 能否分成2个a,2个b,2个c 也即每个 ...
- UVA 12293 - Box Game(博弈)
UVA 12293 - Box Game 题目链接 题意:两个盒子,一開始一个盒子有n个球.一个仅仅有1个球,每次把球少的盒子中球消掉,把多的拿一些球给这个盒子.最后不能操作的输(球不能少于1个),A ...
- UVA 2474 - Balloons in a Box 爆搜
2474 - Balloons in a Box 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...
- 【Luogu P1168】【Luogu P1801&UVA 501】中位数&黑匣子(Black Box)——对顶堆相关
Luogu P1168 Luogu P1801 UVA 501(洛谷Remote Judge) 前置知识:堆.优先队列STL的使用 对顶堆 是一种在线维护第\(k\)小的算法. 其实就是开两个堆,一个 ...
- UVA 4855 Hyper Box
You live in the universe X where all the physical laws and constants are different from ours. For ex ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- OAuth2理解
OAuth2: 1.他是针对特定问题的一种解决方案 OAuth2主要可以解决两个问题: (1)开放系统间的授权问题 例如:当你想要一个打印机器去打印自己百度网盘中的照片时,该机器并没有访问自己百度网盘 ...
- VMware vSphere 虚拟化平台的安装及使用
首先解释一下这些名词, vSphere是什么? vSphere 是VMware公司发布的一整套产品包,是VMware公司推出的一套服务器虚拟化解决方案,包含VMware ESXi hypervisor ...
- C#实现JWT无状态验证的实战应用
前言 本文主要介绍JWT的实战运用. 准备工作 首先我们创建一个Asp.Net的,包含MVC和WebApi的Web项目. 然后使用Nuget搜索JWT,安装JWT类库,如下图. 设计思路 这里我们简单 ...
- PAT-1154(Vertex Coloring )+map使用+vector建图+set的使用
Vertex Coloring PAT-1154 #include<iostream> #include<cstring> #include<string> #in ...
- 不用typsescript也能使用类型增强功能
由于 JS 的弱类型.宽松的编写规范.以及开发工具的弱鸡支持,我们在维护前人的代码时,经常会出现不知道某一个方法或字段命名来自于哪里,一定要在全局搜索以后慢慢筛查才能找到 同样我们在使用接口返回的对象 ...
- 2020年12月-第02阶段-前端基础-CSS Day02
CSS Day02 复合选择器 后代选择器 并集选择器 1. CSS复合选择器 理解 理解css复合选择器分别的应用场景 为什么要学习css复合选择器 CSS选择器分为 基础选择器 和 复合选择器 , ...
- 【Arduino学习笔记06】上拉电阻和下拉电阻
为什么要用上拉电阻和下拉电阻?--避免输入引脚处于"悬空"状态 下图是一个没有使用上拉电阻/下拉电阻的电路图: 在按键没有按下时,要读取的输入引脚没有连接到任何东西,这种状态就称为 ...
- CSS基础 和 font字体、背景属性连写 与 清除浮动方法
1.伪类 1. :link 2. :visited 3. :hover(重要) 4. :active 5. :focus(input标签获取光标焦点) 2.伪元素 1.:first-letter 2. ...
- 【老孟Flutter】Flutter 2的新功能
老孟导读:昨天期待已久的 Flutter 2.0 终于发布了, Flutter Web和Null安全性趋于稳定,Flutter桌面安全性逐渐转向Beta版! 原文链接:https://medium.c ...
- Java数组:多维数组(二维),Arrays类,冒泡排序
Arrays类数组工具类:java.util.ArraysArrays类中的方法都是static修饰的静态方法,在使用的时候可以直接使用类名进行调用,而"不用"使用对象来调用 具有 ...