【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;
}
【45.65%】【codeforces 560B】Gerald is into Art的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【codeforces 734F】Anton and School
[题目链接]:http://codeforces.com/problemset/problem/734/F [题意] 给你两个数组b和c; 然后让你找出一个非负数组a满足题中所给关系; [题解] 有个 ...
- 【codeforces 65A】Harry Potter and Three Spells
[题目链接]:http://codeforces.com/problemset/problem/65/A [题意] 你有3种魔法; 1.可以将a单位的石头变成b单位的铅 2.可以将c单位的铅变成d单位 ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【搜索】【并查集】Codeforces 691D Swaps in Permutation
题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【链表】【模拟】Codeforces 706E Working routine
题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,Q个操作,每次把两个同样大小的子矩阵交换,子矩阵左上角坐标分别 ...
- 【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions
题目链接: http://codeforces.com/problemset/problem/710/D 题目大意: 两个等差数列a1x+b1和a2x+b2,求L到R区间内重叠的点有几个. 0 < ...
随机推荐
- [NOI.AC#41]最短路 线性基
链接 题解 如果不加边,两个点之间的长度是唯一的(只能走最短路径),因为如果重复走,就异或掉了. 因此,先DFS预处理一下每个点到根的距离 \(d[x]\) ,那么 \(x,y\) 之间的距离为 $d ...
- thinkphp验证码(总结之后,效率非常好)
thinkphp验证码(总结之后,效率非常好) 一.总结 1.总结:总结之后,效率非常好,复习的时候也才方便,也能深入到细处,非常方便建立熟悉感和突破使用困境 2.验证码使用中文集或者繁体集设置:这个 ...
- C#中流,字节,字符,字符串
首先要明白它们本身是由什么组成的: 流:二进制 字节:无符号整数 字符:Unicode编码字符 字符串:多个Unicode编码字符 那么在.net下它们之间如何转化呢? 一般是遵守以下规则: 流-&g ...
- golang sync.RWMutex
sync.RWMutex package main import ( "fmt" "runtime" "sync" ) func click ...
- Spring CORS
转载:Spring MVC 4.2 增加 CORS 支持 http://spring.io/blog/2015/06/08/cors-support-in-spring-framework http: ...
- 洛谷 P1893 山峰暸望
P1893 山峰暸望 题目描述 一天,Bessie在眺望美丽的威斯康星的群山的时候,她突然产生了疑问:那座山是最宽的? 她决定在地平线上,利用她的新式大量程山峰高度测量仪依次做N (1 <= N ...
- 计科1111-1114班第一次实验作业(NPC问题——回溯算法、聚类分析)
实验课安排 地点: 科技楼423 时间: 计科3-4班---15周周一上午.周二下午 计科1-2班---15周周一下午.周二晚上(晚上时间从18:30-21:10) 请各班学委在实验课前飞信通知大家 ...
- windows.location属性(常用知识点)
location对象 含有当前URL的信息. 属性 href 整个URL字符串.protocol 含有URL第一部分的字符串,如http:host 包含有URL中主机名:端口号部分的字符串.如//ww ...
- vue 自定义分页组件
vue2.5自定义分页组件,可设置每页显示条数,带跳转框直接跳转到相应页面 Pagination.vue 效果如下图: all: small(只显示数字和上一页和下一页): html <temp ...
- 00092_字符输出流Writer
1.字符输出流Writer (1)既然有专门用于读取字符的流对象,那么肯定也有写的字符流对象: (2)查阅API,发现有一个Writer类,Writer是写入字符流的抽象类.其中描述了相应的写的动作. ...