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

原文連接:https://www.cnblogs.com/xwl3109377858/p/11564279.htmlhtml

Codeforces Round #587 (Div. 3)ios

C - White Sheetide

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).spa

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).code

                                          

 

 

                       Example of three rectangles.htm

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.blog

Inputthree

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.ci

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.get

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 }
相關文章
相關標籤/搜索