zoukankan      html  css  js  c++  java
  • uva 1587 Box(思路)

    给6个矩形的长和宽(或者宽和长),问这六个矩形能否组成一个长方体.

    思路比较简单,不过需要注意的地方有点多.

    首先由于长和宽的顺序为止,所以要处理一下(一开始只处理了后来读入的五组,没有处理单独读入的第一组,差评)

    然后要判断能否分成两两相同的三组.

    如果能,枚举8种可能的相等的情况.

      1 /*************************************************************************
      2     > File Name: code/uva/1587.cpp
      3     > Author: 111qqz
      4     > Email: rkz2013@126.com 
      5     > Created Time: 2015年09月22日 星期二 12时20分58秒
      6  ************************************************************************/
      7 
      8 #include<iostream>
      9 #include<iomanip>
     10 #include<cstdio>
     11 #include<algorithm>
     12 #include<cmath>
     13 #include<cstring>
     14 #include<string>
     15 #include<map>
     16 #include<set>
     17 #include<queue>
     18 #include<vector>
     19 #include<stack>
     20 #include<cctype>
     21 #define y1 hust111qqz
     22 #define yn hez111qqz
     23 #define j1 cute111qqz
     24 #define ms(a,x) memset(a,x,sizeof(a))
     25 #define lr dying111qqz
     26 using namespace std;
     27 #define For(i, n) for (int i=0;i<int(n);++i)  
     28 typedef long long LL;
     29 typedef double DB;
     30 const int inf = 0x3f3f3f3f;
     31 
     32 struct Q
     33 {
     34     int w,h;
     35 }a,b,c,q[10];
     36 bool ok ( int i)
     37 {
     38     
     39     if (q[i].w==q[i+1].w&&q[i].h==q[i+1].h) return true;
     40     return false;
     41 }
     42 
     43 bool solve ()
     44 {
     45     if (a.w==b.w&&a.h==c.h&&b.h==c.w) return true;
     46     if (a.w==b.h&&a.h==c.h&&b.w==c.w) return true;
     47     if (a.w==b.w&&a.h==c.w&&b.h==c.h) return true;
     48     if (a.w==b.h&&a.h==c.w&&b.w==c.h) return true;
     49 
     50     if (a.w==c.w&&a.h==b.h&&b.w==c.h) return true;
     51     if (a.w==c.w&&a.h==b.w&&b.h==c.h) return true;
     52     if (a.w==c.h&&a.h==b.w&&b.h==c.w) return true;
     53     if (a.w==c.h&&a.h==b.h&&b.w==c.w) return true;
     54     return false;
     55 }
     56 
     57 bool cmp(Q a,Q b)
     58 {
     59     if (a.w<b.w) return true;
     60     if (a.w==b.w&&a.h<b.h) return true;
     61     return false;
     62 }
     63 int main()
     64 {
     65   #ifndef  ONLINE_JUDGE 
     66    freopen("in.txt","r",stdin);
     67   #endif
     68 
     69    while (scanf("%d %d",&q[0].w,&q[0].h)!=EOF)
     70     {
     71     if (q[0].w>q[0].h) swap(q[0].w,q[0].h);
     72     for ( int i = 1 ; i < 6 ; i++)
     73     {
     74        // scanf("%d %d",&w[i],&h[i]);           //蠢了..开始开了两个数组读的长和宽.排序后对应关系就打乱了233
     75         scanf("%d %d",&q[i].w,&q[i].h);
     76         if (q[i].w>q[i].h) swap(q[i].w,q[i].h);
     77     }
     78     
     79     bool flag = true;
     80     sort(q,q+6,cmp);
     81 //    for ( int i = 0 ; i < 6 ; i++) cout<<q[i].w<<" "<<q[i].h<<endl;
     82     for ( int i = 0 ; i < 6 ; i = i + 2)
     83     {
     84         if (!ok(i))
     85         {
     86         flag = false;
     87         break;
     88         }
     89     }
     90     if (!flag)
     91     {
     92         puts("IMPOSSIBLE");
     93         continue;
     94     }
     95     a.w = q[0].w; a.h=q[0].h;
     96     b.w = q[2].w; b.h=q[2].h;
     97     c.w = q[4].w; c.h=q[4].h;
     98 //    cout<<a.w<<" "<<a.h<<endl;
     99 //    cout<<b.w<<" "<<b.h<<endl;
    100 //    cout<<c.w<<" "<<c.h<<endl;
    101 
    102     if (solve())
    103     {
    104         puts("POSSIBLE");
    105     }
    106     else
    107     {
    108         puts("IMPOSSIBLE");
    109     }
    110 
    111     }
    112   
    113    
    114  #ifndef ONLINE_JUDGE  
    115   fclose(stdin);
    116   #endif
    117     return 0;
    118 }
    View Code
  • 相关阅读:
    如何实现数据库实体生成工具
    linux samba 与 Windows 共享文件
    CUnit 的使用
    Xml Document与 xml反序列化
    c语言多文件链接
    c 递归获取文件与目录
    gdb输入输出重定向
    C 链表实现
    Log4net多程序集使用独立的配置文件
    Sqlite 学习 编译sqlite静态库,供其他项目调用
  • 原文地址:https://www.cnblogs.com/111qqz/p/4829426.html
Copyright © 2011-2022 走看看