【45.65%】【codeforces 560B】Gerald is into Art

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Gerald bought two very rare paintings at the Sotheby’s auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a1 × b1 rectangle, the paintings have shape of a a2 × b2 and a3 × b3 rectangles.

Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?

Input
The first line contains two space-separated numbers a1 and b1 — the sides of the board. Next two lines contain numbers a2, b2, a3 and b3 — the sides of the paintings. All numbers ai, bi in the input are integers and fit into the range from 1 to 1000.

Output
If the paintings can be placed on the wall, print “YES” (without the quotes), and if they cannot, print “NO” (without the quotes).

Examples
input
3 2
1 3
2 1
output
YES
input
5 5
3 3
3 3
output
NO
input
4 2
2 3
1 2
output
YES
Note
That’s how we can place the pictures in the first test:

这里写图片描述

And that’s how we can do it in the third one.
这里写图片描述

【题目链接】:http://codeforces.com/contest/560/problem/B

【题解】

先固定第一个矩形在左下角(靠边);这样肯定是最好的方法;
然后枚举第二个矩形要放在哪里;
两个矩形都有两种形态.即竖着放还是横着放;
处理一下就好;
时间复杂度是O(N^2);
->第二个矩形只有判断有没有越界就可以了;

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int MAXN = 1e3+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);

int n,x;
int a1,b1,a2,b2,a3,b3;
bool bo[MAXN][MAXN];

bool get_ans()
{
    rep1(i,1,a1)
        rep1(j,1,b1)
            if (bo[i][j])
            {
                if (i+a3-1<=a1 && j+b3-1<=b1) return true;
                if (i+b3-1<=a1 && j+a3-1<=b1) return true;
//                if (get_ans1(i,j,a3,b3)) return true;
//                if (get_ans1(i,j,b3,a3)) return true;
            }
    return false;
}

bool chushi(int ta,int tb)
{
    memset(bo,false,sizeof bo);
    rep1(i,1,a1)
        rep1(j,1,b1)
            bo[i][j] = true;
    rep1(i,1,ta)
        rep1(j,1,tb)
            if (!bo[i][j])
                return false;
            else
                bo[i][j] = false;
    return true;
}

int main()
{
    //freopen("F:\rush.txt","r",stdin);
    rei(a1);rei(b1);
    rei(a2);rei(b2);
    rei(a3);rei(b3);
    if (chushi(a2,b2))
        if (get_ans())
        {
            puts("YES");
            return 0;
        }
    if (chushi(b2,a2))
        if (get_ans())
        {
            puts("YES");
            return 0;
        }
    puts("NO");
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7626849.html