BOX

时间:2024-11-05 15:04:32

题目连接:http://acm.tju.edu.cn/toj/showp2392.html2392.   Box


Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 846   Accepted Runs: 304    Multiple test files

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.

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 consists of six lines. Each line describes one pallet and contains two integer numbers w and h (1 ≤ wh ≤ 10 000) — width and height of the pallet in millimeters respectively.

Output

Write a single word "POSSIBLE" to the output 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 Sample Output
1345 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
POSSIBLE
1234 4567
1234 4567
4567 4321
4322 4567
4321 1234
4321 1234
IMPOSSIBLE

Source: Northeastern European 2004

题解: :对面进行排序,比较相邻的两个面是否相同,当两个面相同的时候看第一个面和第三个面是否有公共边,最后看最后的面可以和前两个面连起来吗

重复的东西可以写成函数 不易出错,

这里注意,如果最后满足题意的有一种情况的时候,flag定义成false,有一个满足就更新成true,

而要找所有条件都满足的时候,开始将flag定义成true,有一个不满足就更新成false

其实刷水题还是有用的,gaga.

 #include <cstdio>
#include <algorithm>
using namespace std; struct pg{
int x, y;
bool operator < (const pg a) const {
return x == a.x ? y < a.y : x < a.x;
}
}p[];
bool ch(int x, int y, pg tm)
{
if(x > y) swap(x, y);
return x == tm.x && y == tm.y;
} int main()
{
while(~scanf("%d %d", &p[].x, &p[].y))
{
for(int i = ; i < ; i++) scanf("%d %d", &p[i].x, &p[i].y);
for(int i = ; i < ; i++) if(p[i].x > p[i].y) swap(p[i].x, p[i].y);
sort(p, p+);
if(p[].x != p[].x || p[].y != p[].y || p[].x != p[].x || p[].y != p[].y || p[].x != p[].x || p[].y != p[].y)
{
puts("IMPOSSIBLE");
continue;
}
pg a = p[], b = p[], c = p[];
int t1, t2;
bool flag = false;
if(a.x == b.x && ch(a.y, b.y, c)) flag = true;
if(a.x == b.y && ch(a.y, b.x, c)) flag = true;
if(a.y == b.x && ch(a.x, b.y, c)) flag = true;
if(a.y == b.y && ch(a.x, b.x, c)) flag = true;
if(flag) puts("POSSIBLE");
else puts("IMPOSSIBLE");
}
return ;
}