UVALive 7267

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
给4个矩形;问能不能从其中任选3个形成一个大的矩形
思路:暴力
任选其中2个看能不能匹配,再去和第三个匹配
#include <bits/stdc++.h>
using namespace std;
int cw,ch;
struct rec
{
    int w,h;

};
rec a[10];
bool judge(int i,int j)
{
    for(int k=1; k<=4; k++)
    {
        if(i==k||k==j)
            continue;
        if(ch==a[k].h||cw==a[k].w||ch==a[k].w||cw==a[k].h)
            return true;
    }
    return false;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=1; i<=4; i++)
        {
            scanf("%d%d",&a[i].w,&a[i].h);
        }
        bool flag=false;
        for(int i=1; i<=4; i++)
        {
            for(int j=1; j<=4; j++)
            {
                if(i==j)
                    continue;
                if(a[i].w==a[j].w)
                {
                    cw=a[i].w;
                    ch=a[i].h+a[j].h;
                    if(judge(i,j))
                        flag=true;

                }
                if(a[i].h==a[j].w)
                {
                    cw=a[j].w;
                    ch=a[i].w+a[j].h;
                    if(judge(i,j))
                        flag=true;
                }
                if(a[i].w==a[j].h)
                {
                    cw=a[j].h;
                    ch=a[i].h+a[j].w;
                    if(judge(i,j))
                        flag=true;

                }
                if(a[i].h==a[j].h)
                {
                    ch=a[i].h;
                    cw=a[i].w+a[j].w;
                    if(judge(i,j))
                        flag=true;
                }

            }
        }
        if(flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
}

转载于:https://www.cnblogs.com/AC-dream/p/5747984.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值