Блог пользователя aliassadi

Автор aliassadi, история, 5 лет назад, По-английски

Hi.
I want to solve a problem. There is n points upper than x = 0 (not on x = 0). We can put circles with radius r on x axis (Which mean their center lie on x axis). We must use minimum circles to cover all points. a point is covered if lie on a circle or be inside a circle. in input n and n points and r is given.
Example:
Input:

3 2   // 3 point and r = 2    
1 2   // point 1    
-3 1  // point 2    
2 1   // point 3  

output:

2   

This is problem. We have one second time limit and we can not do lots of working.
I do a greedy approach. I start from most left. I choose from most left and choose a circle. my point should lie on that circle. I think this is best answer. then skip all point which covered with that circle and do it again until finish all point.
However I get wrong answer. I think a lot and I found some problem. I couldn't find a better way.
Is it possible to help me? I think that I can map this problem to a famous algorithm but I couldn't find it!!!
I'm sorry for bad English too. Thanks.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If you're sorting points only by their x-coordinate, it may be that the leftmost point doesn't give you the leftmost circle that you need to place.

Say for example that you have a radius 100 and you have points (1, 1) and (2, 100). If you center your circle at (2, 0) it will cover both points, but if you consider (1, 1) first you'll place your circle somewhere between (98, 0) and (100, 0) and it will miss the second point.