【45.65%】【codeforces 560B】Gerald is into Art
来源:互联网 发布:qq老密数据库下载 编辑:程序博客网 时间:2024/05/17 01:18
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;}
- Codeforces 560B Gerald is into Art
- CodeForces 560B Gerald is into Art
- CodeForces 560B Gerald is into Art
- CodeForces - 560B Gerald is into Art
- 【45.65%】【codeforces 560B】Gerald is into Art
- CodeForces#313 B. Gerald is into Art
- Codeforces 560B Gerald is into Art 放矩形
- Codeforces 560B Gerald is into Art(构造性算法)
- Codeforces 560B Gerald is into Art(相片摆放模拟)
- CodeForces 560B Gerald is into Art【水题】
- Codeforces 560B Gerald is into Art【思维、分类讨论】
- B. Gerald is into Art
- B. Gerald is into Art
- Codeforces Round #313 (Div. 2) B. Gerald is into Art
- Codeforces Round #313 (Div. 2)-B. Gerald is into Art
- Code Forces 560 B. Gerald is into Art(水~)
- Code Forces 560B Gerald is into Art
- Gerald is into Art
- iReport中产生二维条码(zxing)
- 深度学习word2vec笔记之算法篇
- 信号编程之信号发送及信号处理函数遇到不可重入函数
- 不要消费信任
- Linux下的fdisk用法
- 【45.65%】【codeforces 560B】Gerald is into Art
- 安装Ubuntu系统,你如何分区滴~?
- freeswitch之多分机顺振
- Java 求余操作符
- SVN linux下的安装与使用
- ubuntu14.04 node.js快速安装
- 深入解析struts.xml配置的实现原理
- ANDROID 秒级编译 FREELINE
- java实现直播功能或者视频监控,想用RPT协议,怎样把RPT协议集成到项目中