Overlapping rectangles判断两个矩形是否重叠的问题 C++

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Overlapping rectangles判断两个矩形是否重叠的问题 C++相关的知识,希望对你有一定的参考价值。

Given two rectangles, find if the given two rectangles overlap or not.

A rectangle is denoted by providing the x and y co-ordinates of two points: the left top corner and the right bottom corner of the rectangle.

Note that two rectangles sharing a side are considered overlapping.

技术分享

Input:

The first integer T denotes the number of test cases. For every test case, there are 2 lines of input. The first line consists of 4 integers: denoting the co-ordinates of the 2 points of the first rectangle. The first integer denotes the x co-ordinate and the second integer denotes the y co-ordinate of the left topmost corner of the first rectangle. The next two integers are the x and y co-ordinates of right bottom corner. Similarly, the second line denotes the cordinates of the two points of the second rectangle.


Output:

For each test case, output (either 1 or 0) denoting whether the 2 rectangles are overlapping. 1 denotes the rectangles overlap whereas 0 denotes the rectangles do not overlap.


Constraints:

1 <= T <= 10

-10000 <= x,y <= 10000

T denotes the number of test cases. x denotes the x co-ordinate and y denotes the y co-ordinate.


Example:

Input:
2
0 10 10 0
5 5 15 0
0 2 1 1
-2 -3 0 2

Output:
1
0

下面是我的代码实现:

 




以上是关于Overlapping rectangles判断两个矩形是否重叠的问题 C++的主要内容,如果未能解决你的问题,请参考以下文章

计蒜客 Overlapping Rectangles (离散化)

497. Random Point in Non-overlapping Rectangles

2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Overlapping Rectangles 矩形并面积和

LeetCode 528. Random Pick with Weight / 497. Random Point in Non-overlapping Rectangles

习题 7-6 UVA - 12113Overlapping Squares

在java中判断一个点是不是在一个有斜度的矩形内的 Rectangle的用法