Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

2023-06-08,,

C. White Sheet

There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x1,y1), and the top right — (x2,y2).

After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x3,y3), and the top right — (x4,y4). Coordinates of the bottom left corner of the second black sheet are (x5,y5), and the top right — (x6,y6).

Example of three rectangles.
Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.

Input
The first line of the input contains four integers x1,y1,x2,y2 (0≤x1<x2≤106,0≤y1<y2≤106) — coordinates of the bottom left and the top right corners of the white sheet.

The second line of the input contains four integers x3,y3,x4,y4 (0≤x3<x4≤106,0≤y3<y4≤106) — coordinates of the bottom left and the top right corners of the first black sheet.

The third line of the input contains four integers x5,y5,x6,y6 (0≤x5<x6≤106,0≤y5<y6≤106) — coordinates of the bottom left and the top right corners of the second black sheet.

The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.

Output
If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".

Input


Output

NO

Input


Output

YES

思路:判断白色矩阵是否四个顶点都在黑色矩阵内,如果不是,直接YES;否则,判断是否白色矩阵被某一个黑色矩阵包含,是就NO,不是的话判断两个黑色矩阵是否相离,是就NO,不是就YES;【借鉴博客的.】

AC代码:

 #include<bits/stdc++.h>

 using namespace std;

 int x1,x2,x3,x4,x5,x6;
int y1,y2,y3,y4,y5,y6;
int check(int x,int y){
int flag=;
if(x>=x3&&x<=x4&&x>=y3&&x<=y4)
flag=;
if(flag){
return flag;
}
if(x>=x5&&x<=x6&&x>=y5&&x<=y6)
flag=;
return flag;
}
int check1(){
int flag=;
if(x1>=x3&&y1>=y3&&x2<=x4&&y2<=y4){
flag=;
}
return flag;
}
int check2(){
int flag=;
if(x1>=x5&&y1>=y5&&x2<=x6&&y2<=y6){
flag=;
}
return flag;
}
int main(){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
scanf("%d%d%d%d",&x3,&y3,&x4,&y4);
scanf("%d%d%d%d",&x5,&y5,&x6,&y6);
int a=check(x1,y1);
int b=check(x1,y2);
int c=check(x2,y2);
int d=check(x2,y1);
if(!a||!b||!c||!d){ // 判断是否四边形是否有点没有被覆盖
printf("YES");
return ;
}
if(check1()||check2()){ // 判断是否有矩形可将其完全覆盖的
printf("NO");
return ;
}
if(max(x3,x5)>min(x4,x6)||max(y3,y5)>min(y4,y6)){ // 判断是否矩形分离
printf("YES");
}else{
printf("NO");
}
return ;
}

Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}的相关教程结束。

《Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}.doc》

下载本文的Word格式文档,以方便收藏与打印。