UVa 1587 Box

大水题一发  弄清长方体的几个面的关系就行了

#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 6;

struct rec{ int l, w;} r[N];
bool cmp(rec a, rec b)
{
    return a.w < b.w || (a.w == b.w && a.l < b.l);
}

int main()
{
    int a, b, ok;
    while(~scanf("%d%d", &r[0].w, &r[0].l))
    {
        ok = 1;
        if(r[0].w > r[0].l) swap(r[0].w, r[0].l);
        for(int i = 1; i < 6; ++i)
        {
            scanf("%d%d", &r[i].w, &r[i].l);
            if(r[i].w > r[i].l) swap(r[i].w, r[i].l);
        }

        sort(r, r + N, cmp);
        for(int i = 0; i < N; i += 2)
            if(r[i].w != r[i + 1].w || r[i].l != r[i + 1].l) ok = 0;
        if(r[0].w != r[2].w || r[0].l != r[4].w || r[2].l != r[4].l) ok = 0;

        puts(ok ? "POSSIBLE" : "IMPOSSIBLE");
    }
    return 0;
}

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 ( 1wh10 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
时间: 2024-11-03 05:20:11

UVa 1587 Box的相关文章

UVa 1587 Box 盒子

这道题的链接:https://vjudge.net/problem/UVALive-3214 给定6个矩形的长和宽wi与hi(1<=wi, hi<=1000), 判断它们能否构成长方体的6个面 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

uva 1587 Box(思路)

给6个矩形的长和宽(或者宽和长),问这六个矩形能否组成一个长方体. 思路比较简单,不过需要注意的地方有点多. 首先由于长和宽的顺序为止,所以要处理一下(一开始只处理了后来读入的五组,没有处理单独读入的第一组,差评) 然后要判断能否分成两两相同的三组. 如果能,枚举8种可能的相等的情况. 1 /************************************************************************* 2 > File Name: code/uva/1587.

Uva 1587 - Box ( 思维 )

题意: 给定6个矩形的长和宽wi和hi(1<=wi,hi<=1000),判断它们能否构成长方形的6个面. 脑洞打开~~ /* 1 1 1 1 2 2 2 2 3 3 3 3 */ 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cstdlib> 6 #include<cmath> 7 #

uva 1587(Box UVA - 1587)

题目大意是给定6个数对,每个数对代表一个面的长和宽,判断这6个面是否能构成一个长方体. 这种题一看很复杂,但是只要不想多了实际上这就是一个水题... 首先说明一下判断的思路: 1.长方体是有三个对面的,所以先把这三个对面找出来(因为输入的长和宽是不确定的,所以先把每一组输入的两个数按照从大到小进行调整(这里建议开一个结构体数组)).调整完之后,自己写一个cmp的函数用来sort,cmp是先比较长(按照升序或者降序是无所谓的,随你)然后如果长相等那么就比较宽(按照和长一样的顺序比较). 2.你以为

uva 12293 - Box Game(组合游戏)

题目链接:uva 12293 - Box Game 题目大意:有两个盒子,第一个盒子装有n个球,第二个盒子装又1个球,每次操作将少的盒子中的球全部拿掉,并从另一个盒子中取一些球放入该盒子,不能使另一个盒子中球的个数为0.两人轮流操作,问说最后谁胜. 解题思路:n如果为2i?1那么先手必败. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; bool judge (

UVA 12293 - Box Game(博弈)

UVA 12293 - Box Game 题目链接 题意:两个盒子,一开始一个盒子有n个球,一个只有1个球,每次把球少的盒子中球消掉,把多的拿一些球给这个盒子,最后不能操作的输(球不能少于1个),Alice先手,问谁赢 思路:博弈,题目其实可以转化为,给定一个n,每次把减少1到n/2的数字,最后谁是1谁就输了,那么可以去递推前几项找个规律,或者推理,都可以发现只要是2^i - 1的数字Bob就赢,否则Alice赢 代码: #include <stdio.h> #include <stri

UVA - 12293 Box Game (规律)

Description  Box Game  There are two identical boxes. One of them contains n balls, while the other box contains one ball. Alice and Bob invented a game with the boxes and balls, which is played as follows: Alice and Bob moves alternatively, Alice mo

UVA 12293 Box Game(博弈入门)

题目链接:Box Game 题面:            12293 Box Game There are two identical boxes. One of them contains n balls, while the other box contains one ball. Alice and Bob invented a game with the boxes and balls, which is played as follows: Alice and Bob moves al

uva 591 Box of Bricks

Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. Look, I've built a wall!'', he tells his older sister Alice.Nah, you should make all stacks the same height. Then you would ha