原文链接:https://www.cnblogs.com/xwl3109377858/p/11564279.html
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), 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.
题意:题意就是给你一个白色矩形、两个黑色矩形的左下角和右上角的坐标,
问你这两个黑色矩形是否把白色矩形全部覆盖了,注意是全部覆盖。
思路:刚开始我想的解法就是暴力把白色矩形的四条边上点的坐标判一下是否在两个黑色矩形的任一个之内,
只要有一个点不在就没有全部覆盖,但是在对样例的时候发现,第三个样例对不上,
原来是因为暴力判断边上坐标点少了,不能每次+1仅判断int的坐标,会漏掉一部分,
应该用double的坐标每+0.5判断一下,就可以全部判完,可以自己画图看一下。具体看代码。
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<set> 8 #include<vector> 9 #include<queue> 10 #include<list> 11 #include<stack> 12 using namespace std; 13 #define ll long long 14 const int mod=1e9+7; 15 const int inf=1e9+7; 16 17 //const int maxn= 18 19 double x1,x2,x3,x4,x5,x6; 20 21 double y1,y2,y3,y4,y5,y6; 22 23 inline bool judge1(double x,double y) 24 { 25 if((x>=x3&&x<=x4)&&(y>=y3&&y<=y4)) 26 return true; 27 else 28 return false; 29 } 30 31 inline bool judge2(double x,double y) 32 { 33 if((x>=x5&&x<=x6)&&(y>=y5&&y<=y6)) 34 return true; 35 else 36 return false; 37 } 38 39 int main() 40 { 41 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); 42 43 cin>>x1>>y1>>x2>>y2; 44 45 cin>>x3>>y3>>x4>>y4; 46 47 cin>>x5>>y5>>x6>>y6; 48 49 int flag=0; 50 51 for(double i=x1;i<=x2;i+=0.5) 52 { 53 if((judge1(i,y1)||judge2(i,y1))&&(judge1(i,y2)||judge2(i,y2))) 54 ; 55 else 56 { 57 flag=1; 58 break; 59 } 60 } 61 62 for(double i=y1;i<=y2;i+=0.5) 63 { 64 if((judge1(x1,i)||judge2(x1,i))&&(judge1(x2,i)||judge2(x2,i))) 65 ; 66 else 67 { 68 flag=1; 69 break; 70 } 71 } 72 73 if(flag==0) 74 cout<<"NO"<<endl; 75 else 76 cout<<"YES"<<endl; 77 78 return 0; 79 }
原文地址:https://www.cnblogs.com/xwl3109377858/p/11564279.html