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;
}

发布了28 篇原创文章 · 获赞 4 · 访问量 4831

猜你喜欢

转载自blog.csdn.net/xxw2016/article/details/79265294
Box
今日推荐