#P8133. Maximum Points in a Thick Line
Maximum Points in a Thick Line
Maximum Points in a Thick Line
In 1921, Alfred Watkins coined the term "ley lines" to denote straight lines connecting various places of historical or geographical interest. One common criticism is that if you have a thick pencil, you can easily draw a "line" (which in reality is an infinite strip of non‐zero width) that connects many points, even if the points are not perfectly collinear.
In this problem, you are given a set of points on a plane. Each point has two unique coordinates, and no three points are collinear. In addition, you are given the thickness of your pencil. When you draw a line with your pencil, it produces an infinite strip of width t. A point is considered to be on the line if its perpendicular distance to the center line is at most t/2.
Your task is to determine the largest number of points that can lie inside some such infinite strip (i.e. some orientation and position of a line drawn with a pencil of thickness t).
Note: The strip can be arbitrarily rotated and translated.
Mathematical formulation: Given a set of points \((x_i, y_i)\) for \(i=1,2,\dots,n\) and a pencil thickness \(t>0\), find the maximum \(k\) such that there exists a line \(L\) for which at least \(k\) points satisfy
[ |d_i - d_0| \leq \frac{t}{2} \quad \text{for each of the } k \text{ points}, ]
where \(d_i\) is the signed perpendicular distance of the \(i\)th point to the line \(L\), and \(d_0\) is chosen optimally (by sliding the line parallel to itself).
inputFormat
The first line of the input contains two numbers: an integer n
(\(1 \le n \le 1000\)) representing the number of points, and a floating-point number t
representing the thickness of the pencil (> 0).
Following this, there are n
lines. Each line contains two space-separated floating-point numbers representing the \(x\) and \(y\) coordinates of a point.
You may assume that the points have unique coordinates and no three points are collinear.
outputFormat
Output a single integer representing the maximum number of points that lie on some thick line drawn with a pencil of thickness t.
sample
3 1
0 0
1 0
0 1
2
</p>