POJ-3241 Object Clustering (Manhattan Minimum Spanning Tree)

There are n point sets on the plane. Now divide them into k sets, so that each point in each set has at least one Manhattan distance between the points of this set not more than X, and find the minimum X.

Analysis:

The Title requires that the longest edge of the minimum spanning tree in Manhattan of each set should not exceed X after partitioning the set, so it is easy to think of the n-k edge of the minimum spanning tree in Manhattan of the entire set of points.

A brief description of the method for solving the minimum spanning tree of Manhattan distance:

If two or two points are directly edged, the total number of edges is O(n^2). With the time complexity O(N+E) Prim algorithm, the time complexity O(E*logE) kruskal algorithm will be timed out (where N is the number of points, E is the number of edges).

The idea here is to reduce the complexity of edges to O(n), because a large number of edges are useless, as long as the nearest point is connected every 45 degrees.

If B and C are in the right 45 degree area of y axis and | AB | <= | AC |, we can get | BC | <= | AC |, so | AB | + | BC | <= | AC | | AB or | AC|+|BC |, that is, the shortest distance between A, B and C is the sum of the shortest distance in every 45 degree direction (where the distance is Manhattan distance):

According to the above, we can only connect each point to the edge of the point with the smallest distance in eight directions.

Because the sides are bidirectional, we only need to connect R1, R2, R3 and R4. For example: (pictured above) B is the minimum distance point of A R1, A is the minimum distance point of B R5. We can know the relationship between AB as long as R 1 and R 5 are not connected, that is, A is connected to B.

The train of thought has come out, so how to deal with it? Let's first consider one direction, such as R1 (analogy of the other three directions).

Point B(x1,y1) in the region of point A(x0,y0) satisfies x1 (> x0) and Y1 X1 > Y0 x0. So B is on R1 of A.

The point closest to A in the R 1 region of A is also the point where x+y is the smallest among the points satisfying the conditions. So we can sort all the points in X coordinates and then disperse them in y_x.

Maintain the smallest x+y corresponding point (i.e. the smallest maintenance interval) of y_x larger than the current point with a line segment tree or tree array, and use a tree array here because the code is simpler.

Thus, the R1 region is processed, while the points of the other three regions need only be reversed and symmetrically transformed into the R1 region. For example, in R2 region, R3 can be obtained with respect to y=x symmetry (swap (x, y). Then R4 can be obtained with respect to X axis symmetry (x=-x), and R4 with respect to y=x symmetry.