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 ...
随机推荐
- 学习String源码的部分方法
先看构造器: private final char value[]; //char类型的数组 以下均会用到 private int hash; //缓存字符串的哈希值 //以下均会用到 public ...
- Spring Cloud基础
1.网站架构演变过程 传统架构(单点应用SSM或SSH)→分布式架构(项目拆分)→SOA架构(面向服务架构)→微服务架构 2.微服务概述 2.1SOA架构 面向服务的架构(SOA)是一个组件模型,它将 ...
- Go benchmark 一清二楚
前言 基准测试(benchmark)是 go testing 库提供的,用来度量程序性能,算法优劣的利器. 在日常生活中,我们使用速度 m/s(单位时间内物体移动的距离)大小来衡量一辆跑车的性能,同理 ...
- 机械硬盘换固态硬盘&重装系统
起初 笔记本电脑购买于2016年底,i7四代处理器,940M显卡,4G内存,500G固态硬盘,这样的配置已经跟不上使用需求了.于是先把内存条升级成了单根8G金士顿内存条,豁然发现使用chrome浏览器 ...
- python+unittest+ddt数据驱动进行接口自动化测试
所谓数据驱动测试,简单的理解为数据的改变从而驱动自动化测试的执行,最终引起测试结果的改变.通过使用数据驱动测试的方法,可以在需要验证多组数据测试场景中,使用外部数据源实现对输入输出与期望值的参数化,避 ...
- SnowNLP——获取关键词(keywords(1))
一.SnowNLP的获取文本关键词 前面介绍了SnowNLP的获取关键词的方法,这里再重现一下 1 from snownlp import SnowNLP 2 # 提取文本关键词,总结3个关键词 3 ...
- Fastjson1.2.24RCE漏洞复现
Fastjson1.2.24RCE漏洞复现 环境搭建 这里用的Vulhub靶场 cd /vulhub/fastjson/1.2.24-rce docker-compose up -d 报错 ERROR ...
- 2019 GDUT Rating Contest I : Problem E. Convention
题面: E. Convention Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 十分钟学会Scratch图形化编程
一.概要 Scratch是麻省理工学院开发的供儿童或者初学者学习编程的开发平台.其通过点击并拖拽的方式,完成编程,可以使儿童或者成人编程初学者学习编程基础概念等.Scratch是一款积木式图形编程软件 ...
- JVM之对象回收
finalize /** *此代码演示了两点: *1.对象可以在被GC时自我拯救. *2.这种自救的机会只有一次,因为一个对象的finalize()方法最多只会被系统自动调用一次 */ public ...