How to define a straight line that intersects as many rectangles as possible?

I am looking for an algorithm to solve this problem besides reinforcement learning and those that take a long time.

N rectangles are placed on the xy plane. How many rectangles can a straight line pass at the maximum?

Input

The number of rectangles is n.
The upper left coordinate of the rectangle of the number i is given by x [i], y [i].
Its width and height are specified by w [i], h [i].

Example

n
x[0] y[0] w[0] h[0]
x[1] y[1] w[1] h[1]
x[n-1] y[n-1] w[n-1] h[n-1]

      

The rule

  • 0 <n <= 1000
  • Each rectangle is placed at 0 <= x <= 10000, 0 <= y <= 10000.
  • The coordinate must be whole.
  • Width and height must be greater than 1 and an integer.
  • The rectangles can overlap.
  • A straight line can convey the vertices of rectangles to rectangles.
  • The line must not go through (0, 0).

Tips

Option 1:

Input
4
0    0    1    1
9999 0    1    1
0    9999 1    1
9999 9999 1    1

Output
2

      

Case 2:

Input
6
2    1    4    3
1   10    1    3
5    7    5    4
8    8    3    2
13   4    3    1
17   1    1   14

Output
5

      

+3


source to share





All Articles