Mysterious Antiques in Sackler Museum

滴答滴答题目链接

题意:有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");
    }
}

猜你喜欢

转载自blog.csdn.net/chen_zan_yu_/article/details/83851726