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

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 } 

原文地址:https://www.cnblogs.com/pengge666/p/11567344.html

时间: 2024-08-03 23:00:16

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

Codeforces Round #587 (Div. 3) C - White Sheet

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564279.html Codeforces Round #587 (Div. 3) 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 w

Codeforces Round #587 (Div. 3) B - Shooting

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564214.html Codeforces Round #587 (Div. 3) B - Shooting Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a ta

Codeforces Round #587 (Div. 3) D - Swords

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564317.html Codeforces Round #587 (Div. 3) D -Swords There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people

Codeforces Round #587 (Div. 3)

C. White Sheet 一道基础的几何题  给定三个矩形的左下角坐标和右上角坐标,第一块是白色矩形,第二第三都是黑色矩形,问白色矩形是否被黑色矩形完全覆盖.思路就是根据点判断分类讨论. 1.如果白色矩形的四个点没有全部被覆盖了   那么直接输出“NO” 2.如果白色矩形的四个点都被覆盖了,那么就再判断下黑色的矩形有没有交集 1 #include <math.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #inclu

Codeforces Round #324 (Div. 2) (快速判断素数模板)

蛋疼的比赛,当天忘了做了,做的模拟,太久没怎么做题了,然后C题这么简单的思路却一直卡到死,期间看了下D然后随便猜了下,暴力了下就过了. A.找一个能被t整除的n位数,那么除了<=10以外,其他都可以用长度为n的10或100,1000 ... 来往上加几个数而得到 #include <iostream> #include <stdio.h> #include <set> #include <algorithm> #include <string.h

White Sheet (矩形面积模板) (Codeforces Round #587 (Div. 3) )

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)(0,0),

Codeforces Round #587 (Div. 3) F Wi-Fi(线段树+dp)

题意:给定一个字符串s 现在让你用最小的花费 覆盖所有区间 思路:dp[i]表示前i个全覆盖以后的花费 如果是0 我们只能直接加上当前位置的权值 否则 我们可以区间询问一下最小值 然后更新 #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int N = 2e5+7; typedef long long ll; const ll mod

Codeforces Round #112 (Div. 2) C Another Problem on Strings

题目链接:Codeforces Round #112 (Div. 2) C Another Problem on Strings 题意:给出一个只含0,1的序列,求序列中和为n的子序列有多少个. 思路:预处理出序列的前缀和,然后枚举序列时,记录(vis)该位置之前已有的前缀和,再查询(sum[i]-n)的个数,即以该位置为结束的子序列和为n的个数. 注意:vis数组中0应该始终存在,初始化vis[0]=1(why?,因为sum[i]本身就等于n算一个方法数). 举一反三:类似的就已经可以得到,任

水题 Codeforces Round #303 (Div. 2) A. Toy Cars

题目传送门 1 /* 2 题意:5种情况对应对应第i或j辆车翻了没 3 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 4 3: if both cars turned over during the collision. 5 是指i,j两辆车,而不是全部 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath> 11 #