Problem Description
Problem Analysis
Because the radar must be installed on the x-axis
so if y>d, output -1
Draw a circle centered at the point with radius d
intersecting the x-axis at two points
If the radar lies between the two points
it can cover this point
Since the intervals may overlap
we only need to place points in the overlapping part
to cover as many points as possible
Thus the problem can be transformed into
given several intervals
how many points are needed so that each interval contains at least one point
So we arrive at a greedy strategy
sort the intervals by their right endpoints
when comparing, assume a radar is built at the first right endpoint
mark its coordinate as t
then if the left endpoint of the next interval is after this point
update t to the right endpoint of the next interval
and increment cnt++
| |