zoukankan      html  css  js  c++  java
  • Uva 1587.Box

    思路比较清晰吧

    如果可以拼成长方体,要满足:

    1. 保证6个长方形能够成对相同(相同)
    2. 有3组不同的数据(长、宽、高),且每组有4个

    使用排序进行排序。

    相邻两个排序,确保每一个长方形都是以(宽,长)的顺序记录(sort排序时,开始位置是第一个位置,结束为止是最后一个数据的下一个位置)

    然后整体排序,每4个一组,进行比较

    输出

     1 #include <cstdio>
     2 #include <algorithm>
     3 using namespace std;
     4 
     5 #define REP(n) for(int o=0;o<n;o++)
     6 
     7 bool Do();
     8 
     9 int main(){
    10     //freopen("in.txt","r",stdin);
    11     while(Do());
    12     return 0;
    13 }
    14 
    15 bool Do(){
    16     int a[13];
    17     if(scanf("%d",&a[1])==EOF)
    18         return false;
    19     REP(11)
    20         scanf("%d",&a[o+2]);
    21     REP(6)
    22         sort(&a[1+o*2],&a[3+o*2]);
    23 
    24     bool can=true;
    25 
    26     for(int i=0;i<6;i++){
    27         int cnt=0;
    28         for(int j=0;j<6;j++){
    29             if(a[1+i*2]==a[1+j*2]&&a[2+i*2]==a[2+j*2])
    30                 cnt++;
    31         }
    32         if(cnt<2){
    33             can=false;
    34             break;
    35         }
    36     }
    37 
    38     if(can){
    39         sort(a+1,a+13);
    40         REP(3)
    41             if(!(a[1+o*4]==a[2+o*4]&&a[2+o*4]==a[3+o*4]&&a[3+o*4]==a[4+o*4]))
    42                 can=false;
    43     }
    44     printf("%s
    ",can?"POSSIBLE":"IMPOSSIBLE");
    45     return true;
    46 }
  • 相关阅读:
    Aspect Oriented Programming
    jsp01
    监听器
    Java编写验证码
    servlet07
    MySQL02
    MySQL01
    Java的jdk1.6与jre1.8中存在的差异
    登陆验证和二级联动
    ajax和json
  • 原文地址:https://www.cnblogs.com/ohyee/p/5153576.html
Copyright © 2011-2022 走看看