zoukankan      html  css  js  c++  java
  • UVaLive 7267 Mysterious Antiques in Sackler Museum (if-else,枚举)

    题意:给定四个矩形,要求从中选出三个,能不能拼成一个矩形。

    析:说到这个题,我还坑了队友一次,读题读错了,我直接看的样例,以为是四个能不能组成,然后我们三个就拼命想有什么简便方法,后来没办法了,直接暴力。

    康神写了6000多B的代码,全是循环和if-else,我们画出五种情况。。。。然而并不是这样,

    只要几个if-else就够,因为就3个,两种情况。

    代码如下;

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e6 + 5;
    const int mod = 1e9 + 7;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    P a[4];
    
    bool judge(int i, int j, int k){
        if(a[i].first == a[j].first && a[i].first == a[k].first)  return true;
        if(a[i].first == a[j].first && a[i].first == a[k].second)  return true;
        if(a[i].first == a[j].second && a[i].first == a[k].first)  return true;
        if(a[i].first == a[j].second && a[i].first == a[k].second)  return true;
    
        if(a[i].second == a[j].first && a[i].second == a[k].first)  return true;
        if(a[i].second == a[j].first && a[i].second == a[k].second)  return true;
        if(a[i].second == a[j].second && a[i].second == a[k].first)  return true;
        if(a[i].second == a[j].second && a[i].second == a[k].second)  return true;
    
        if(a[i].first == a[j].first + a[k].first && a[j].second == a[k].second)  return true;
        if(a[i].first == a[j].first + a[k].second && a[j].second == a[k].first)  return true;
        if(a[i].first == a[j].second + a[k].second && a[j].first == a[k].first)  return true;
        if(a[i].first == a[j].second + a[k].first && a[j].first == a[k].second)  return true;
    
        if(a[i].second == a[j].first + a[k].first && a[j].second == a[k].second)  return true;
        if(a[i].second == a[j].first + a[k].second && a[j].second == a[k].first)  return true;
        if(a[i].second == a[j].second + a[k].second && a[j].first == a[k].first)  return true;
        if(a[i].second == a[j].second + a[k].first && a[j].first == a[k].second)  return true;
        return false;
    }
    
    int main(){
        int T;  cin >> T;
        while(T--){
           for(int i = 0; i < 4; ++i){
                scanf("%d %d", &a[i].first, &a[i].second);
           }
           bool ok = false;
           for(int i = 0; i < 4; ++i)
             for(int j = 0; j < 4; ++j){
                if(i == j)  continue;
                for(int k = 0; k < 4; ++k){
                    if(k == i || k == j)  continue;
                    if(judge(i, j, k)) ok = true;
                }
             }
          if(ok)  puts("Yes");
          else puts("No");
        }
        return 0;
    }
    
  • 相关阅读:
    php内核为变量的值分配内存的几个宏
    php7 引用成为一种类型
    function参数
    execvp php-fpm reload使用的函数
    fastcgi
    php-fpm定时器
    php 类继承
    php 对象 调用静态方法
    php unset变量
    php5数组与php7数组区别
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5750874.html
Copyright © 2011-2022 走看看