Gerald is into Art

Gerald is into Art

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 andb3 — 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).

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

地址:http://codeforces.com/contest/560/problem/B

思路:题意很简单就是把2个长方形放在一个大的长方形的里,看是否能成功。
刚开始,在想的时候,忘了只有个2个长方形,感觉好难。最后再看了下是2个。。
于是就简单了,但是也没有想到什么好办法。直接考虑所以的情况,应该是8种。
   最后就AC了,百度了下好像大家都是这么做的,至于多个长方形的情况还有待考虑,还有别人的代码细节写的比我简单些

#include <cstdio>

using namespace std;

int main(){

        int a1, b1;
        int a2, b2;
        int a3, b3;

        while(scanf("%d%d", &a1, &b1) != EOF){
                scanf("%d%d", &a2, &b2);
                scanf("%d%d", &a3, &b3);

                int flag = 0;

                if((a2 * b2 + a3 * b3) > (a1 * b1)){
                        flag = 1;
                }
                else{
                        if((a2 + a3) <= a1  && b2 <= b1 && b3 <= b1){
                        }
                        else if((a2 + b3) <= a1 && b2 <= b1 && a3 <= b1){
                        }
                        else if((a2 <= a1 && a3 <= a1 && (b2 + b3) <= b1)){
                        }
                        else if(a2 <= a1 && b3 <= a1 && (b2 + a3) <= b1){
                        }
                        else if((b2 + a3) <= a1 && a2 <= b1 && b3 <= b1){
                        }
                        else if((b2 + b3) <= a1 && a2 <= b1 && a3 <= b1){
                        }
                        else if(b2 <= a1 && a3 <= a1 && (a2 + b3) <= b1){
                        }
                        else if(b2 <= a1 && b3 <= a1 && (a2 + a3) <= b1){
                        }
                        else{
                                flag = 1;
                        }
                }
                if(1 == flag){
                        printf("NO\n");
                }else{
                        printf("YES\n");
                }
        }
        return 0;
}

    

        2015-07-26  18:15:47

你可能感兴趣的:(int)