UVa 1587 - Box

来源:互联网 发布:linux打开oracle服务 编辑:程序博客网 时间:2024/04/30 03:12

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,即长>宽;
然后对六个面进行排序,按照长从大到小排序,长相同,按宽排序;
接下来进行判断,长方体含有“三对”面,并且一对面中的长或宽等于另一对面中的长或宽,符合条件的即为长方体。

#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;}
0 0
原创粉丝点击