Kick Start 2019 Round A Parcels

Subject to the effect

$ R \ times C $ grid, the distance between the lattice taking the Manhattan distance. Some of the grid is the post office. Now we can not put up a post office grid becomes post office, ask each grid to a maximum of Manhattan distance of the nearest post office is the smallest number.

data range

  • $ 1 \ R \ 250 $
  • $ 1 \ C \ the $ 250
  • 100 groups of test data
  • Time limit: 15 s

analysis

Obviously you can half the answer.

Geometric perspective

Consider the whole point of the plane (also known as grid). To a lattice point of a Manhattan distance is no greater than the contour points possessive $ k $ is a square rotated by 45 ° (For any point, the set of points within a manhattan distance of K form a square rotated by 45 degrees.) or call diamond.

Consider all the shortest distance from the existing post office is more than $ k $ grid point, referred to as "non-covered point" does not cover each point is associated with a paragraph on said diamond. If all the rhombic the intersection is not empty, then just take a little from the intersection as a new post office can be.

Difficulty of this method lies in the intersection of two diamond is not easy to calculate. But we can coordinate transformation, the original diamond becomes a square. Square intersection is easily calculated.
This transformation in the algorithm contest circles as the Manhattan distance turn Chebyshev distance.

For the two plane $ (x_1, y_1) $, $ (x_2, y_2) $; both DMC Chebyshev distance is defined as the ratio of $ \ max (| x_1 - x_2 |, | y_1 - y_2 |) $.

Corresponding to the coordinate transformation is $ (x, y) \ longleftrightarrow (x + y, x - y) $.

Algebra perspective

The root of the coordinate transformation is defined Manhattan distance:

Two $ (x_1, y_1) $, $ (x_2, y_2) $ Manhattan distance is simply the maximum of the four values ​​of the following

$ (x_1 - x_2) + (y_1 - y_2) $
$ (x_1 - x_2) + (y_2 - y_1) $
$ (x_2 - x_1) + (y_1 - y_2) $
$ (x_2 - x_1) + (y_2 - y_1) $
亦即
$(x_1 + y_1) - (x_2 + y_2)$
$(x_1 - y_1) - (x_2 - y_2) $
$(x_2 - y_2) - (x_1 - y_1) $
$(x_2 + y_2) - (x_1 + y_1)$
四者中的最大值。

于是有
\begin{equation}
|x_1 - y_1 | + |y_1 - y_2| = \max(|(x_1 + y_1) - (x_2 + y_2)|, |(x_1 - y_1) - (x_2 - y_2)|) \label{E:1}
\end{equation}

Use \ eqref {E: 1} style, we can solve this problem from the perspective of Algebra (rather than geometric perspective).

May wish to coordinate a new post office deemed to $ (x_2, y_2) $, the coordinates of the post office is not yet covered by existing points deemed $ (x_1, y_1) $.

Transformed into the
presence or absence of point $ (x_2, y_2) $, satisfying when $ (x_1, y_1) $ runs over the uncovered point, \ eqref: values {E 1} is never more than $ k $, in other words \ eqref {E : 1} is not less than the maximum value of $ k $.

Note that when \ eqref {E: 1} when the maximum value, $ x_1 + y_1 $, $ x_1 - y_1 $ will take most value (i.e., taking the maximum or minimum value).

Therefore, we can not cover the first traverse point $ (x_1, y_1) $, calculated $ x_1 + y_1 $, $ x_1 - most value y_1 $, and then enumerate all possible new post office $ (x_2, y_2) $, seeking \ eqref {E: 1} of formula maximum, is determined.

Guess you like

Origin www.cnblogs.com/Patt/p/11617460.html