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");
        }
    }
  • 相关阅读:
    系统设计与架构笔记:对我新公司网站的技术架构初解
    与国内某知名互联网公司交流后的心得
    系统架构:Web应用架构的新趋势---前端和后端分离的一点想法
    为什么做java的web开发我们会使用struts2,springMVC和spring这样的框架?
    我设计的网站的分布式架构
    Python Day 46 前端 、HTML5介绍、HTML标签、标签的嵌套规则、CSS3介绍、CSS代码中书写位置(重点)、CSS基础选择器、
    Python Day 45 手撸ORM框架
    Python Day 44 Mysql数据库备份及优化(六)
    Python Day 43 Mysql基础语法(五)sqlalchemy、创建表、增删改查、高级查询操作、正向反向查询
    Python Day 42 Mysql基础语法(四)、存储引擎、索引、慢日志查询、普通日志记录(general log)、权限管理、explain工具
  • 原文地址:https://www.cnblogs.com/Ritchie/p/5741823.html
Copyright © 2011-2022 走看看