您的位置:首页 > 其它

BOX

2015-08-09 09:41 197 查看
题目连接:http://acm.tju.edu.cn/toj/showp2392.html2392. BoxTime 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.



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 ≤ w, h ≤ 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 InputSample 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[6];
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[0].x, &p[0].y))
{
for(int i = 1; i < 6; i++) scanf("%d %d", &p[i].x, &p[i].y);
for(int i = 0; i < 6; i++) if(p[i].x > p[i].y) swap(p[i].x, p[i].y);
sort(p, p+6);
if(p[0].x != p[1].x || p[0].y != p[1].y || p[2].x != p[3].x || p[2].y != p[3].y || p[4].x != p[5].x || p[4].y != p[5].y)
{
puts("IMPOSSIBLE");
continue;
}
pg a = p[0], b = p[2], c = p[4];
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 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: