I'm looking for an algorithm to solve this problem other than reinforcement learning and those that take a long time to run.
On the x-y plane, n rectangles are placed. How many rectangles can a straight line pass through at maximum?
Input
The number of rectangle is n.
The upper left coordinate of number i rectangle is given by x[i], y[i].
Its width and height are given 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]
Rule
- 0 < n <= 1000
- Each rectangle is placed in 0 <= x <= 10000, 0 <= y <= 10000.
- The coordinate must be integer.
- Width and height must be bigger than 1 and integer as well.
- Rectangles can overlap.
- A straight line can pass throgh vertexs of rectangles.
- The straight line doesn't have to pass through (0, 0).
Hints
Case1:
Input
4
0 0 1 1
9999 0 1 1
0 9999 1 1
9999 9999 1 1
Output
2
Case2:
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