uva-1587 BOX

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 ≤ 10000) — 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

 

分析:

3种情况,1:正方体。2:有两个面是正方形。3:普通情况,见输入

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
    int a[100111][3];
    int j,k;
    int i=1;
    while(~scanf("%d %d",&a[i][1],&a[i][2]))
    {
        int count1=0,count2=0;
        int flag=0;
        int num=0;
        if(i%6==0)
        {
            for(j=i-5; j<=i; j++)
            {
                flag=0;
                count1=0,count2=0;
                for(k=i-5; k<=i; k++)
                {
                    if(k==j)
                        continue;
                    if((a[j][1]==a[k][1]&&a[j][2]==a[k][2])||(a[j][1]==a[k][2]&&a[j][2]==a[k][1]))
                    {
                        count1++;
                    }
                    if((a[j][1]==a[k][1]&&a[j][2]!=a[k][2])||(a[j][1]==a[k][2]&&a[j][2]!=a[k][1])||(a[j][1]!=a[k][1]&&a[j][2]==a[k][2])||(a[j][1]!=a[k][2]&&a[j][2]==a[k][1]))
                    {
                        count2++;
                    }
                }
                if((count1==1&&count2==4)||(count1==5&&count2==0)||(count1==3&&count2==2))
                {
                    num++;
                }
            }
            if(num==6)
                printf("POSSIBLE\n");
            else
                printf("IMPOSSIBLE\n");
        }
        i++;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值