Mysterious Antiques in Sackler Museum (模拟)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a1046765624/article/details/82915307

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

题目大概:

给出四个矩形的长宽,问是否有一种方案选出其中的三种组成一个大矩形。

思路:

分两种情况模拟。

1.三个矩形一排。

2.一个大矩形,旁边两个小矩形。

代码:

#include <bits/stdc++.h>

using namespace std;
#define ll long long
const int maxn=1e5+10;
const int mod=1e9+7;
int a[4][2];
int go(int x)
{
    int u=a[x][0];
    int v=a[x][1];
    for(int i=0;i<4;i++)
    {
        if(i==x)continue;
        for(int j=0;j<4;j++)
        {
            if(j==x)continue;
            if(i==j)continue;
            for(int k1=0;k1<2;k1++)
            {
                for(int k2=0;k2<2;k2++)
                {

                    if(a[i][k1]==a[j][k2])
                    {
                        int sum=a[i][k1^1]+a[j][k2^1];
                        if(sum==u||sum==v)
                        {
                            return 1;
                        }
                    }
                }
            }
        }
    }
    return 0;
}
int pan()
{
    for(int i=0; i<2; i++)
    {
        for(int j=0; j<2; j++)
        {
            for(int k=0; k<2; k++)
            {
                if(a[0][i]==a[1][j]&&a[1][j]==a[2][k])
                {
                    return 1;
                }
                if(a[0][i]==a[1][j]&&a[1][j]==a[3][k])
                {
                    return 1;
                }
                if(a[0][i]==a[2][j]&&a[2][j]==a[3][k])
                {
                    return 1;
                }
                if(a[1][i]==a[2][j]&&a[2][j]==a[3][k])
                {
                    return 1;
                }
            }
        }
    }
    return 0;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0; i<4; i++)
        {
            for(int j=0; j<2; j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        if(pan())
        {
            printf("Yes\n");
            continue;
        }
        int flag=0;
        for(int i=0; i<4; i++)
        {
            if(go(i))
            {
                printf("Yes\n");
                flag=1;
                break;
            }
        }
        if(flag)continue;
        printf("No\n");
    }
    return 0;
}
/*
100
1 1 1 2 1 2 1 4
3 3 5 1 2 3 1 1
1 3 1 3 1 3 1 3
*/

猜你喜欢

转载自blog.csdn.net/a1046765624/article/details/82915307