What is discretization?

Source: Internet
Author: User

In the Dalian cyber competition yesterday, after the competition, I learned about the report and made it discrete .. Let's get an introduction from Daniel ..

Reprinted from: http://www.matrix67.com/blog/archives/108

If the most frequently asked question by oibh this year is a bipartite graph, the most asked question last year is discretization. For "What Is discretization", you can search for posts and find various arguments, such as "post-sorting" and "approximate processing of sitting objects. Which one is right? All are correct. The key lies in that this can be fully explained only by some examples and many explanations.
Discretization isProgramA very common technique in design, which can effectively reduce the time complexity. The basic idea is to "only consider the values I need" in many possible cases ". Below I will use three examples to illustrate how to use discretization to improve an inefficient or even impossible implementation.Algorithm.

in the competition of algorithm art and informatics, Huang Liang gave a classic example, which I think is suitable for introducing the idea Of discretization. This problem is uva10173 (http://acm.uva.es/p/v101/10173.html), the question is very simple, given the coordinates of N points on the plane, find the minimum rectangular area that can cover all these points. This problem is hard to solve. This rectangle can be skewed (the edges do not have to be parallel to the coordinate axis ).
the skew here is not easy to handle, because we do not know how many degrees the rectangle will eventually tilt. If we know that the angle of the rectangle is α, the answer is very simple: the four sides of the rectangle must be tied to a certain point at the hour. That is to say, if we already know the slope of the four sides, we only need to keep these sides approaching the point set from the outside until they reach a certain point. You don't have to know how to implement this. You just need to understand that this can be calculated in some way. After all, our focus is on the following process.
our algorithm is clear: We can enumerate the angle of the rectangle. For each angle, we can calculate the smallest area of the rectangle, and finally take a minimum value.
is this algorithm correct? We cannot say whether it is correct, because it cannot be implemented at all. The angle of a rectangle is a real number. It is impossible to enumerate every situation. We say that the angle of the rectangle is a "continuous" variable, which is the root cause of the inability to enumerate this angle. We need a way to change this "continuous" variable into a value and a "discrete" variable. This process is also called discretization.
we can prove that the rectangle with the smallest area requires not only one vertex on each of the four sides, but also two or more vertices on each side. Imagine that if there is only one vertex on each side, we can always rotate this rectangle to make it "loose", so that we can get a smaller rectangle. Therefore, we find that the slope of an edge of a rectangle must be the same as that of a link between two points. If we calculate the inclination of all the straight lines that pass through two points, the α value can only be the inclination angle or the angle after 90 degrees (when the straight line is tilted in the "\" direction) so C (n, 2. We said that this "dip" has been "discretization. Although this algorithm still has room for optimization, we have achieved the goal described at the beginning of this article.

we can also use the idea Of discretization to narrow down the range of some coordinates, although they are already integers (discrete. Recently, it seems that vijos is quite popular. I just took two questions about vijos.
voj1056 (http://www.vijos.cn/Problem_Show.asp? Id = 1056) is always a classic problem of discretization. N rectangles on a given plane (the coordinates are integers, and there may be overlapping parts between rectangles. The common idea is to open a two-dimensional Boolean array equivalent to the two-dimensional coordinate to simulate the "Overwrite" of the rectangle (fill the position of the rectangle with true ). Unfortunately, this idea has some problems here, because the coordinate range in this question is quite large (the coordinate range is an integer ranging from-10 ^ 8 to 10 ^ 8 ). However, we found that the number of rectangles n <= 100 is far smaller than the coordinate range. Each rectangle "uses" two values on the horizontal and vertical coordinates. The coordinates of the 100 rectangles do not use the 200 values between-10 ^ 8 and 10 ^ 8. That is to say, there are actually only a few useful values. These values will be used as new coordinate values to re-divide the whole plane, saving some coordinate values in the middle without affecting. We can "discretization" the coordinate range to the number between 1 and 200, so a two-dimensional array of 200*200 is enough. The implementation method is as described in "post-sorting" at the beginning of this article ". Sort the abscissa (or ordinate) and map it to an integer ranging from 1 to 2N. At the same time, record the actual distance between every two adjacent coordinates of the new coordinate before discretization. This question also has room for optimization.
in the end, let's briefly talk about an example of an application beyond the calculation of ry (actually, it is still the discretization of coordinates ). Voj1238 (http://www.vijos.cn/Problem_Show.asp? In id = 1238), an array of the same size as the time range is enabled to store the location of the time period. This method is very dangerous in space. Once the time range is larger, blind space overhead will cause memory limit exceeded. We can use discretization to avoid this situation. We sort all the given time coordinates once, and then use the start point and end point of the time period to calculate the number of games at each time point, only the number of experience values added at one time is multiplied by the actual difference between the two adjacent time points after sorting. In this way, an array of 1. N is enough.

Discretization is widely used and will be used in the future.

Supplement:
In the voj1056 example, some people still don't understand it.
I will send one and pay attention to how the 10*7 array on the left is equivalent to the two 4*4 arrays on the right.

Matrix67 original
Reprinted please indicate the source

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.