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的更多相关文章

  1. uva 1587(Box UVA - 1587)

    题目大意是给定6个数对,每个数对代表一个面的长和宽,判断这6个面是否能构成一个长方体. 这种题一看很复杂,但是只要不想多了实际上这就是一个水题... 首先说明一下判断的思路: 1.长方体是有三个对面的 ...

  2. 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 如果要构成一个长方体的话, ...

  3. 【每日一题】 UVA - 1587 Box 二维有点偏序的感觉

    一开始用set存xjb分类讨论,然后wa, 然后简化了一点,改用vector,然wa 最后又发现没有初始化,然wa wa了一个半小时 最后看了题解orz 然后找了一组样例把自己的代码改对了 /* 1 ...

  4. 【习题 3-10 UVA - 1587】Box

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举某个顶角的三个相邻面就好. 看看这三个相邻面有没有对应的面. 以及3个相邻面的6个边. 能否分成2个a,2个b,2个c 也即每个 ...

  5. UVA 12293 - Box Game(博弈)

    UVA 12293 - Box Game 题目链接 题意:两个盒子,一開始一个盒子有n个球.一个仅仅有1个球,每次把球少的盒子中球消掉,把多的拿一些球给这个盒子.最后不能操作的输(球不能少于1个),A ...

  6. UVA 2474 - Balloons in a Box 爆搜

    2474 - Balloons in a Box 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...

  7. 【Luogu P1168】【Luogu P1801&UVA 501】中位数&黑匣子(Black Box)——对顶堆相关

    Luogu P1168 Luogu P1801 UVA 501(洛谷Remote Judge) 前置知识:堆.优先队列STL的使用 对顶堆 是一种在线维护第\(k\)小的算法. 其实就是开两个堆,一个 ...

  8. UVA 4855 Hyper Box

    You live in the universe X where all the physical laws and constants are different from ours. For ex ...

  9. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

随机推荐

  1. 1098 Insertion or Heap Sort——PAT甲级真题

    1098 Insertion or Heap Sort According to Wikipedia: Insertion sort iterates, consuming one input ele ...

  2. python基础(2)字符串常用方法

    python字符串常用方法 find(sub[, start[, end]]) 在索引start和end之间查找字符串sub ​找到,则返回最左端的索引值,未找到,则返回-1 ​start和end都可 ...

  3. React组件复用的方式

    React组件复用的方式 现前端的工程化越发重要,虽然使用Ctrl+C与Ctrl+V同样能够完成需求,但是一旦面临修改那就是一项庞大的任务,于是减少代码的拷贝,增加封装复用能力,实现可维护.可复用的代 ...

  4. es命令测试

    1.新建索引并赋值 :put/索引名/文档名/id //文档名后面会逐渐取消 相当表 PUT /test1/type1/1{ "nmae":"hb", &quo ...

  5. Markdown(2)基本语法

    ​ Markdown 是一种轻量级标记语言 , 通过简单的标记语法,使文本内容具有一定的格式 . 一.段落 1. 标题 语法格式: 符号 "#" 可以标记 1~6级标题.一级标题对 ...

  6. Git:版本库建立与状态查看

    版本库又名仓库,英文名repository,可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以追踪历史,或者在将来某个时刻可 ...

  7. 《C++ Primer》笔记 第1章 开始

    输出运算符<< 的计算结果就是其左侧运算对象 std::endl 结束当前行,并将与设备关联的缓冲区中的内容刷到设备中. 程序员常常在调试时添加打印语句.这类语句应该保证"一直& ...

  8. Azure Functions(三)集成 Azure Queue Storage 存储消息

    一,引言 接着上一篇文章继续介绍 Azure Functions,今天我们将尝试绑定 Queue Storage,将消息存储到 Queue 中,并且学会适用于 Azure Functions 的 Az ...

  9. 在不使用外延层的同轴半绝缘衬底材料上制作4H-SIC横向双重注入金属氧化物半导体场效应晶体管

    在不使用外延层的同轴半绝缘衬底材料上制作4H-SIC横向双重注入金属氧化物半导体场效应晶体管 杂志:日本应用物理杂志   在不使用外延层在同轴的半绝缘SIC衬底上制作4H-SIC横向双重注入金属氧化物 ...

  10. 无需编程,通过配置零代码生成CRUD RESTful API

    Hello,crudapi!(你好,增删改查接口!) 本文通过学生对象为例,无需编程,通过配置实现CRUD RESTful API. 概要 CRUD简介 crud是指在做计算处理时的增加(Create ...