BOX
发布日期:2021-10-24 03:36:23 浏览次数:2 分类:技术文章

本文共 2978 字,大约阅读时间需要 9 分钟。

题目连接:
2392.   
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.

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 25842584 6832584 1345683 1345683 13452584 683
POSSIBLE
1234 45671234 45674567 43214322 45674321 12344321 1234
IMPOSSIBLE

Source: 

 

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

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

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

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

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

 

1 #include 
2 #include
3 using namespace std; 4 5 struct pg{ 6 int x, y; 7 bool operator < (const pg a) const { 8 return x == a.x ? y < a.y : x < a.x; 9 }10 }p[6];11 bool ch(int x, int y, pg tm)12 {13 if(x > y) swap(x, y);14 return x == tm.x && y == tm.y; 15 } 16 17 int main()18 {19 while(~scanf("%d %d", &p[0].x, &p[0].y))20 {21 for(int i = 1; i < 6; i++) scanf("%d %d", &p[i].x, &p[i].y);22 for(int i = 0; i < 6; i++) if(p[i].x > p[i].y) swap(p[i].x, p[i].y);23 sort(p, p+6);24 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)25 {26 puts("IMPOSSIBLE");27 continue;28 }29 pg a = p[0], b = p[2], c = p[4];30 int t1, t2;31 bool flag = false;32 if(a.x == b.x && ch(a.y, b.y, c)) flag = true;33 if(a.x == b.y && ch(a.y, b.x, c)) flag = true;34 if(a.y == b.x && ch(a.x, b.y, c)) flag = true;35 if(a.y == b.y && ch(a.x, b.x, c)) flag = true;36 if(flag) puts("POSSIBLE");37 else puts("IMPOSSIBLE");38 }39 return 0;40 }

 

转载于:https://www.cnblogs.com/shanyr/p/4714615.html

转载地址:https://blog.csdn.net/weixin_30687587/article/details/94970696 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:JavaSE--Arrays.copyof
下一篇:计算机科学和PYTHON编程导论_笔记1开方算法

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月05日 12时22分55秒