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

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

Here is given n(n=1000) points on the plane, each described by (x,y). need to place a rectangle of area S on the plane. Sides of a rectangle should be paralel to X and Y axis. required to find maximal number of points that can be contained by a single rectangle.

I need to find maximum O(N^2 * K) solution to solve problem, where K is answer (maximum amount of points among all rectangle with area S),

thanks in advance,

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

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

Do sides lengths can only be integers?

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    not neccessary :\

    • »
      »
      »
      11 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      But coordinates are always integers?

      • »
        »
        »
        »
        11 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        Ok,multiply them by 10^9 ,they are now integers,what then :) ?

        • »
          »
          »
          »
          »
          11 лет назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          First let me show you a solution which works for integer points and in the case when sides have to be integers too.

          Let's find all rectangles of sides a and b, which area is equal to S. There will be d such rectangles, where d is amount of divisors of S. Now consider each rectangle exclusively. While doing that, for each point let's find area in which the top-left corner of rectangle can be placed so it will contain this point. This area will be a rectangle of sides a and b and bottom-right corner in that point. Now all we need to do is find maximum set of rectangle with common part. It can be done in by using segment tree and sweeping technique. So whole complexity is or .

          We can't use such an approach when it's not provided that coordinates as well as sides of rectangle gonna be integers. But do we really can't use it without such a requirements?

          If we change cooridnates to integers by multiplying everything by 109 then our area S has to be multiplied by 1018, so our new area is equal to S' = S * 1018. Moreover sides of our rectangle will be multiplied by 109, so now they are integeres too! Now when everything is integer we can use solution above, but it's complexity gonna be worse cause , so in case of high coordinate precision it won't pass but with precision around 10 - 3 and S around 109 it should be fine.

          Correct last part if I'm wrong, because I'm not 100% sure about it.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

You can iterate through all pairs of points and each time find number points inside this rectangle in average. This can be done with 2d tree range-search or 2d segment tree.So u get

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

You can assume that one point is in the upper right corner. Iterate over all points and fix the upper right corner. For each of the other points find the interval of rectangle heights such that the point is inside the rectangle (if not possible: simply skip the point): O(n). Find the point which is covered by most intervals: . Take the maximum of all outer iterations.

Total complexity: . Not exactly what you were looking for, but at least much better than O(n3)