当前位置 : 主页 > 网页制作 > css >

Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题

来源:互联网 收集:自由互联 发布时间:2021-06-13
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 ha

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

2 2 4 4
1 1 3 5
3 1 5 5

Output

NO

Input

3 3 7 5
0 0 4 6
0 0 7 4

Output

YES

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

AC代码:

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int x1,x2,x3,x4,x5,x6;
 6 int y1,y2,y3,y4,y5,y6;
 7 int check(int x,int y){
 8     int flag=0;
 9     if(x>=x3&&x<=x4&&x>=y3&&x<=y4)
10         flag=1;
11     if(flag){
12         return flag;
13     }
14     if(x>=x5&&x<=x6&&x>=y5&&x<=y6)
15         flag=1;
16     return flag;
17 }
18 int check1(){
19     int flag=0;
20     if(x1>=x3&&y1>=y3&&x2<=x4&&y2<=y4){
21         flag=1;
22     }
23     return flag;
24 }
25 int check2(){
26     int flag=0;
27     if(x1>=x5&&y1>=y5&&x2<=x6&&y2<=y6){
28         flag=1;
29     }
30     return flag;
31 }
32 int  main(){
33     scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
34     scanf("%d%d%d%d",&x3,&y3,&x4,&y4);
35     scanf("%d%d%d%d",&x5,&y5,&x6,&y6);
36     int a=check(x1,y1);
37     int b=check(x1,y2);
38     int c=check(x2,y2);
39     int d=check(x2,y1);
40     if(!a||!b||!c||!d){  // 判断是否四边形是否有点没有被覆盖
41         printf("YES");
42         return 0;
43     }
44     if(check1()||check2()){  // 判断是否有矩形可将其完全覆盖的
45         printf("NO");
46         return 0;
47     }
48     if(max(x3,x5)>min(x4,x6)||max(y3,y5)>min(y4,y6)){  // 判断是否矩形分离
49         printf("YES");
50     }else{
51         printf("NO");
52     }
53     return 0;
54 } 
网友评论