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”.
Examples
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
input
5 2 10 5
3 1 7 6
8 1 11 7
output
YES
input
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
output
YES
Note
In the first example the white sheet is fully covered by black sheets.
In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5,4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.
解题思路:
一道基础的几何题,给定三个矩形的左下角坐标和右上角坐标,第一块是白色矩形,第二第三都是黑色矩形,问白色矩形是否被黑色矩形完全覆盖。思路就是根据点判断分类讨论。
第一类:
白布的四个点没有被完全遮住,直接输出YES
第二类:
继续分类讨论:
1、
白布四个点被遮住,且四个点包含在同一块黑布中。输出NO
2、
白布四个点被遮住,四个点分布在两块黑布中,且黑布没有交集,输出YES
3、
白布四个点被遮住,四个点分布在两块黑布中,且黑布有交集,输出NO
AC代码:
/* `-._: .:' `::: .:\ |\__/| /:: .:' `::: .:.-'
\ : \ |: | / : /
\ :: . `-_______/ :: \_______-' . :: . /
| : :: ::' : :: ::' : :: ::' :: ::' : :: :|
| ;:: ;:: ;:: ;:: ;:: |
| .:' `::: .:' `::: .:' `::: .:' `::: .:' `:|
/ : : : : : \
/______::_____ :: . :: . :: _____._::____\
`----._:: ::' : :: ::' _.----'
`--. ;:: .--'
`-. .:' .-'
\ /
\ /
\/ */
#include <bits/stdc++.h>
const int N=1e6+10;
typedef long long ll;
using namespace std;
bool in(ll x1,ll y1,ll x2,ll y2,ll xx2,ll yy2) // 判断一个点是否在包含在一个矩形里
{
return (x1 >= x2 && y1 >= y2 && x1<= xx2 && y1 <= yy2);
}
int main()
{
ll x1,x2,x3,y1,y2,y3;
ll xx1,xx2,xx3,yy1,yy2,yy3;
while(cin>>x1>>y1>>xx1>>yy1){
cin>>x2>>y2>>xx2>>yy2;
cin>>x3>>y3>>xx3>>yy3;
// 判断白布四个点是否都被黑布覆盖
if((in(x1,y1,x2,y2,xx2,yy2) || in(x1,y1,x3,y3,xx3,yy3)) &&
(in(xx1,y1,x2,y2,xx2,yy2) || in(xx1,y1,x3,y3,xx3,yy3)) &&
(in(x1,yy1,x2,y2,xx2,yy2) || in(x1,yy1,x3,y3,xx3,yy3)) &&
(in(xx1,yy1,x2,y2,xx2,yy2) || in(xx1,yy1,x3,y3,xx3,yy3)))
{
// 判断两块黑布是否有交集
if(in(x3,y3,x2,y2,xx2,yy2) ||
in(xx3,y3,x2,y2,xx2,yy2) ||
in(x3,yy3,x2,y2,xx2,yy2) ||
in(xx3,yy3,x2,y2,xx2,yy2) ||
in(x2,y2,x3,y3,xx3,yy3) ||
in(xx2,y2,x3,y3,xx3,yy3) ||
in(x2,yy2,x3,y3,xx3,yy3) ||
in(xx2,yy2,x3,y3,xx3,yy3) )
cout<<"NO"<<endl;
else
{
// 判断白布是否被**某一块**黑布完全覆盖
if((in(x1,y1,x2,y2,xx2,yy2) && in(xx1,y1,x2,y2,xx2,yy2) && in(x1,yy1,x2,y2,xx2,yy2) && in(xx1,yy1,x2,y2,xx2,yy2)) ||
(in(x1,y1,x3,y3,xx3,yy3) && in(xx1,y1,x3,y3,xx3,yy3) && in(x1,yy1,x3,y3,xx3,yy3) && in(xx1,yy1,x3,y3,xx3,yy3)) )
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
}
else
cout<<"YES"<<endl;
}
return 0;
}