Two rectangles do not intersect

 

Topic connection: http: //www.noobdream.com/DreamJudge/Issue/page/1211/#

 

I thought: subject to the two points given rectangle diagonal (and no provision is being carefully diagonal or anti-diagonal two endpoints).

Regardless of what is given two points, can obtain the coordinates of the lower left and upper right corner of the positive diagonal (of course, choose this only as a reference, you can choose other),

Then you can determine whether two rectangles intersect, are away from, or containing the coordinates (which is included with this set my good hard).

 

 

 

 

 

#include <iostream>
using namespace std;

int x1,y1,x2,y2,x3,y3,x4,y4;

int main () {
    
    the while (~ Scanf ( " % D% D% D% D% D% D% D% D " , & X1, & Y1, & X2, & Y2, & X3, & Y3, & X4, & Y4)) {
         // enter any diagonal after the coordinates, you can get the data we want (that is, the coordinates of the lower left and positive diagonal upper right corner) 
        IF (x1> X2) swap (x1, X2);
         IF (y1> y2) swap (y1, Y2);
         IF (X3> X4) the swap (X3, X4);
         IF (Y3> Y4) the swap (Y3, Y4);
         // excluded from the rectangular phase containing 
        IF (Y2 <Y3 || X2 <X3 Y1 || > || X1 Y4> X4 || (X1 <Y1 X3 && <&& Y3 X2> X4 && Y2> Y4))
            cout << "NO" << endl;
        else {
            cout << "YES" << endl;
        }
         
    }
    
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hello-dummy/p/11716458.html