uva1587

Posted 发牌员

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva1587相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a[8][4],x=0,flag=0,b[20],y=0,z=0,c[20];
    while(~scanf("%d%d",&a[x++][0],&a[x][1]))
    {
        if(a[0][0]==a[x-1][0]||a[0][0]==a[x-1][1])
        {
            flag++;
            b[y++]=x-1;
            if(a[0][0]==a[x-1][0])
                b[y++]=1;
            else
                b[y++]=0;
        }
        else
        {
            c[z++]=x-1;
        }
        if(x==6)
        {
            if(flag<4)
                printf("IMPOSSIBLE\n");
            else
            {
                int flag1=0,ch=0,ku=0;
                for(int i=0; i<6; i++,i++)
                    for(int j=i+2; j<8; j++,j++)
                        if(a[b[i]][b[i+1]]==a[b[j]][b[j+1]])
                        {
                            if(ch)
                                ku=a[b[i]][b[i+1]];
                            else
                                ch=a[b[i]][b[i+1]];
                            flag1++;

                        }
                if(flag1<2)
                    printf("IMPOSSIBLE\n");
                else
                {
                    for(int i=0; i<2; i++)
                        if((ku==a[c[i]][0]&&ch==a[c[i]][1])||(a[c[i]][1]==ku&&a[c[i]][0]==ch))
                            flag1++;
                    if(flag1<4)
                        printf("IMPOSSIBLE\n");
                    else
                        printf("POSSIBLE\n");
                }

 

            }

            x=0;
            flag=0;
            y=0;
            z=0;

        }
    }
    return 0;
}

以上是关于uva1587的主要内容,如果未能解决你的问题,请参考以下文章

Uva 1587.Box

UVA1587

uva1587

UVa 1587 Box 盒子

UVa 1587 - Digit Generator

[算法竞赛入门经典]Kickdown ACM/ICPC NEERC 2004,UVa1587