UVa 1587 - Box
2015-08-16 23:23
549 查看
https://uva.onlinejudge.org/external/15/1587.pdf
1587 Box
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
分析:
给定6个矩形的长和宽,让你判断能否用这六个面组成一个长方体
这道题思路明确了还是不难的,关键是判断方法。
长方体有三种不同的边,我们记为abc,并且记a>b>c,则长方体的六个面必定是ab、ab、ac、ac、bc、bc(按照边的长度排序),符合这种形式的就是一个长方体。
根据题目叙述,重点是怎样把输入的数据转化为这种标准形式,然后进行判断。
首先把每个面的两条边大小弄清楚,如ba转换为ab,即长>宽;
然后对六个面进行排序,按照长从大到小排序,长相同,按宽排序;
接下来进行判断,长方体含有“三对”面,并且一对面中的长或宽等于另一对面中的长或宽,符合条件的即为长方体。
1587 Box
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
分析:
给定6个矩形的长和宽,让你判断能否用这六个面组成一个长方体
这道题思路明确了还是不难的,关键是判断方法。
长方体有三种不同的边,我们记为abc,并且记a>b>c,则长方体的六个面必定是ab、ab、ac、ac、bc、bc(按照边的长度排序),符合这种形式的就是一个长方体。
根据题目叙述,重点是怎样把输入的数据转化为这种标准形式,然后进行判断。
首先把每个面的两条边大小弄清楚,如ba转换为ab,即长>宽;
然后对六个面进行排序,按照长从大到小排序,长相同,按宽排序;
接下来进行判断,长方体含有“三对”面,并且一对面中的长或宽等于另一对面中的长或宽,符合条件的即为长方体。
#include <iostream> #include <sstream> #include <iomanip> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <bitset> #include <string> #include <numeric> #include <algorithm> #include <functional> #include <iterator> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <cctype> #include <complex> #include <ctime> #define INF 0x3f3f3f3f #define eps 1e-6 #define p(x) printf("%d\n", x) #define k(x) printf("Case %d: ", ++x) #define mes(x, d) memset(x, d, sizeof(x)) #define s(x) scanf("%d", &x) /* int gcd(int a,int b) { return ! b ? a : gcd(b,a % b); } */ typedef long long LL; const double pi = acos(-1.0); const long long mod = 1e9 + 7; using namespace std; struct data { int x; int y; }p[2005]; bool cmp(const data &a,const data &b) { if(a.x == b.x) return a.y < b.y; return a.x < b.x; } int main() { //freopen("int.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%d %d",&p[0].x,&p[0].y) == 2) { if(p[0].x > p[0].y) swap(p[0].x , p[0].y); int ok = 0; for(int i = 1;i < 6;i++) { scanf("%d %d",&p[i].x,&p[i].y); if(p[i].x > p[i].y) swap(p[i].x , p[i].y); } sort(p,p + 6,cmp); // for(int i = 0;i < 6;i++) //printf("%d %d\n",p[i].x,p[i].y); 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) ) ok = 1; if(p[0].x != p[2].x || p[2].y != p[4].y || p[1].y != p[4].x) ok = 0; if(ok == 1) printf("POSSIBLE\n"); else printf("IMPOSSIBLE\n"); } return 0; }
相关文章推荐
- 断其一指------Service的使用
- 后序遍历二叉树
- scikit-learn: isotonic regression(保序回归,很有意思,仅做知识点了解,但几乎没用到过)
- HDU 5384——Danganronpa——————【AC自动机】
- centos mysql 安装及配置
- android Fragment实现APP主界面Tab页面切换和点击事件
- HDU--2222--Keywords Search--AC自动机
- 【java编程思想--学习笔记(四)】对象导论
- 第七章--项目范围管理
- SpringMVC Controller 介绍
- C++编译和链接过程的详解
- 进程间通信:管道(pipe)
- strcpy的正确实现
- 设计模式——抽象工厂
- UVa 10340 - All in All
- Layout Management
- 编写高质量代码改善C#程序的157个建议——建议53:必要时应将不再使用的对象引用赋值为null
- VMware Workstation初次安装以及运行Centos6.6所出现的故障和解决办法
- Entity Framework之Code First
- 图像分类算法调研报告