盒子Box UVA1587

来源:互联网 发布:协方差矩阵 编辑:程序博客网 时间:2024/05/29 16:57
  1. #include<cstdio>
  2. #include<set>
  3. #include<string.h>
  4. using namespace std;
  5. struct note{
  6.     int w,h;
  7.     int flag;//用于判断是否被访问过 0表示被访问过
  8.     const bool operator==(const note &n)const {
  9.         return n.w==this->w && n.h==this->h || n.w==this->h&&n.h==this->w;
  10.     }
  11.     note(){this->flag=1;}
  12. };
  13. int main(){
  14.     int w,h;
  15.     while(scanf("%d%d",&w,&h)==2){
  16.        note n1[7];
  17.        set<int>s;
  18.         n1[0].w=w;
  19.         n1[0].h=h;
  20.         for(int i=1;i<6;i++)
  21.         {
  22.         scanf("%d%d",&n1[i].w,&n1[i].h);
  23.         s.insert(n1[i].w);
  24.         s.insert(n1[i].h);
  25.         }
  26.         //此处判断是否有三对 相同 
  27.         int count =0;
  28.         for(int i=0;i<6;i++){
  29.             for(int j=i+1;j<6;j++)
  30.             if(n1[j].flag && n1[i].flag){
  31.                 if(n1[i]==n1[j])
  32.                 {
  33.                 count++;
  34.                 n1[j].flag=0;
  35.                 break;
  36.                 }

  37.             }
  38.             if(count==3)break;
  39.         }

  40.         //输入一组数据中最多有三种不同1、全相同;2、两种(4条相同 、8条相同);3、(4,4,4) 
  41.        int ok=0;
  42.        int length=s.size();
  43.        if(length==1)ok=1;
  44.         else if(length==2){
  45.              int count=0;
  46.              set<int>::iterator iter1=s.begin();
  47.              for(int i=0;i<6;i++)
  48.              {
  49.             if(*iter1==n1[i].w)count++;
  50.                if(*iter1==n1[i].h)count++;
  51.             }
  52.              if(count==4 ||count==8)ok=1;
  53.         }

  54.            else if(length==3){
  55.                int count =0;
  56.                set<int>::iterator iter1=s.begin();
  57.                for(int i=0;i<6;i++)
  58.                {
  59.             if(*iter1==n1[i].w)count++;
  60.                if(*iter1==n1[i].h)count++;
  61.            }
  62.               if(count==4)ok=1;
  63.               }

  64.         if(count==3 && ok)printf("POSSIBLE\n");
  65.         else printf("IMPOSSIBLE\n"); 
  66.     }
  67.     return 0;
  68. }
1 0