Codeforces Round # 587 C. White Sheet (thinking + computational geometry)

Portal

• the meaning of problems

Give a white matrix, the black matrix and then two

If two white black matrix can comprise a matrix, output NO

Otherwise, output YES

• ideas

Computational geometry problems or questions thinking it?

Remembered the title in junior high school geometry in high school do find area

This is similar to that

Included, to discuss the two cases, the other does not contain

① white rectangle in a black rectangle internal

  Analyzing this case, the boundary can be directly

② two black rectangular pattern inside white rectangular combination

  • First, the premise of this situation is that two black rectangles must be able to connect
  • Rectangular white and black rectangles, respectively, have two overlapped overlap areas may overlap in this case,

  Such as white rectangles (1142) 1 Black rectangles (1034) 2 Black rectangles (2053)

    

       Black is a black matrix 2 comprises a joint, with a black area of ​​the intersection of the pink area, the black area of ​​a green region intersects 2

       However, multi-operator region of the green powder, pink white matrix area = Area Area + green - light green area

• Code

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 struct node
 5 {
 6     ll xl,yl,x2,y2;
 7 }a[4],p;
 8 
 9 bool CH(node x,node y )//重合
10 {
11     if(x.xl>=y.xl&&x.x2<=y.x2&&x.yl>=y.yl&&x.y2<=y.y2)
12         return true;
13     return false;
14 }
15 ll XJ(node a,node b)//Intersection 
16  {
 . 17      LL CX1 = max (a.xl, b.xl); 
 18 is      LL Cy1 = max (a.yl, b.yl); 
 . 19      LL CX2 = min (a.x2, b.x2); 
 20 is      LL = Cy2 min (a.y2, b.y2); 
 21 is      IF (CX1> CX2 || Cy1> Cy2) // disjoint 
22 is  
23 is      P = {Node CX1, Cy1, CX2, Cy2}; // intersecting rectangles 
24      return (CX2-CX1) * (Cy2-Cy1); // intersection area 
25  }
 26 is  
27  /// comprises not include nO YES 
28  int main ()
 29  {
 30      for (I = LL. 1 ; I <= . 3 ; I ++ )
 31 is          CIN >> A [I] .xl >> A [I] .yl >> A [I] .x2 >> A [I] .Y2;
 32  
33 is      IF (CH ( A [ . 1 ], A [ 2 ]) || CH (A [ . 1 ], A [ . 3 ])) /// overlapped inside 
34 is      {
 35          the puts ( " NO " );
 36          return  0 ;
 37 [      }
 38 is  
39      IF (XJ (A [ 2 ], A [ . 3 ]) < 0 ) /// 2 do not intersect. 3 
40      {
41         puts("YES");
42         return 0;
43     }
44 
45     if(XJ(a[2],a[3])>=0) ///2 3相交
46     {
47         ll s1=XJ(a[1],a[2]);
48         node p1=p;
49         ll s2=XJ(a[1],a[3]);
50         node p2=p;
51         ll s=(a[1].y2-a[1] .yl) * (A [ . 1 ] .x2-A [ . 1 ] .xl);
 52 is          S = + max (1LL * 0 , XJ (P1, P2)); /// overlap operator will be more at 
53 is  
54 is          IF ( == S2 + S1 S)
 55          {
 56 is              the puts ( " NO " );
 57 is              return  0 ;
 58          }
 59          the else 
60          {
 61 is              the puts ( " YES " );
 62 is              return  0 ;
 63 is          }
 64      }
65 }
66 
67 /**
68 1 1 4 2
69 1 0 3 4
70 2 0 5 3
71 */
View Code

 

Guess you like

Origin www.cnblogs.com/MMMinoz/p/11566721.html