zoukankan      html  css  js  c++  java
  • UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)

    Sackler Museum of Art and Archaeology at Peking University is located on a beautiful site near the West Gate of Peking University campus, and its architecture takes the inspiration from buildings that already exist on campus.

    The collection of Chinese art and artifacts currently housed in this new museum contains more than 10, 000 objects and spans a period of 280, 000 years, from Paleolithic hominids and stone tool remains to costumes, ceramics and paintings of the present era. The collection, which is used for teaching and research purposes, has been acquired during the past seventy years from diverse sources.

    The use of some objects in the museum remains unknown. For example, there are four pieces of rectangular bones which can be dated back to 200, 000 years ago, and no one knows what they were made for. A former NOIer and present ACMer, Mr. Liang in the School of Archaeology and Museology is very interested in those bones, and his tutor told him to use his wildest imagination to guess the usage of them. So, one day, a crazy idea came up to him: were those bones some kind of IQ test tools used by ancient people? Maybe the one who could pick exactly three pieces of those bones to form a larger rectangle was considered smart at that time. So Mr. Liang wanted to write a program to find out how to pass this IQ test imagined by him. Can you also do this?

    Input

    There are several test cases. The first line of input is an integer T (1 ≤ T ≤ 20), indicating the number of test cases. Each test case is in one line and contains 8 integers describing 4 rectangular bones. Each bone is described by 2 integers indicating its width and height.

    All integers in the input are between [1, 1000].

    Output

    For each test case, if Mr. Liang can form a rectangle using those bones in the way he imagined, please print ‘Yes’. If he can’t, print ‘No’ instead. Please note that the area of the new rectangle he forms must be equal to the total area of the bones he picks.

    Sample Input

    2

    1 1 1 1 1 2 2 2

    1 1 2 2 10 10 20 20

    Sample Output

    Yes

    No

    题意:有t组数据,每组给定4个长方形的宽和高,问是否能从中任取三个构成一个严格的长方形,严格的长方形指的是长方形内部没有空缺。

    题解:从中任取三个,进行判断即可,写成结构体用函数判断可以大幅减少代码量。

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <map>
    #include <vector>
    #include <cstring>
    using namespace std;
    struct D{
        int w,h;
        D(int w0=0,int h0=0) {
            w = w0;
            h = h0;
        }
    }data[4];
    D ll(D a,D b){
        if(a.w==b.w) return D(a.w,a.h+b.h);
        else if(a.h==b.w) return D(a.h,a.w+b.h);
        else if(a.h==b.h) return D(a.h,a.w+b.w);
        else if(a.w==b.h) return D(a.w,a.h+b.w);
        else return D(0,0);
    }
    bool pd(D a,D b,D c){
        D tmp;
        tmp = ll(a,b);
        tmp = ll(tmp,c);
        if(tmp.w>0) return true;
        tmp = ll(a,c);
        tmp = ll(tmp,b);
        if(tmp.w>0) return true;
        tmp = ll(b,c);
        tmp = ll(tmp,a);
        if(tmp.w>0) return true;
        return false;
    }
    bool solve() {
        if(pd(data[0],data[1],data[2])) return true;
        if(pd(data[0],data[1],data[3])) return true;
        if(pd(data[0],data[2],data[3])) return true;
        if(pd(data[1],data[2],data[3])) return true;
        return false;
    }
    int main() {
        int T;
        scanf("%d",&T);
        while(T--) {
            for(int i=0;i<4;i++) {
                scanf("%d%d",&data[i].w,&data[i].h);
            }
            if(solve()) puts("Yes");
            else puts("No");
        }
    }
  • 相关阅读:
    CAP分布式
    专职DBA-MySQL数据库开篇
    os.sep
    DocStrings
    Python如何获取脚本的参数
    LVM基础命令
    VoAndEntityTrans
    短信倒计时
    springboot在eclipse上搭建项目一(无页面)
    springboot问题
  • 原文地址:https://www.cnblogs.com/Ritchie/p/5741823.html
Copyright © 2011-2022 走看看