Describe
Given a nxm grid, count the number of triangles that have three points at the lattice point.
Analysis
- The three vertices of a triangle cannot be collinear. This is the starting point.
- The following is a question that has a few points on the line between the original point to Dot (x, y)
- If x, Y is divided by a number g to ensure that the result is an integer, then (x/g, y/g) must be the point of origin to (x, y) on the line
- The distance between the origin and the (x, y) line is equal between each of the two adjacent points. and equals the distance from the origin to the first point.
- Then find the first point and you'll know a few. such as the first point (X0,Y0). So altogether x/x0 a point.
- The first point, the smallest horizontal ordinate, is the largest of G. G Max is gcd (x, y). The horizontal axis of the first point is X/GCD (x, y). Take to the top of the total gcd (x, y) on the whole hour. These points are included (x, y).
- If the three-point collinear condition is not considered, a total of tot = (m+1) * (n+1) points, altogether the scheme number is C (Tot, 3) species.
- You can then enumerate the vectors starting from the origin (x, y), and use GCD to calculate the line between the original point-to-points (x, y) with a few points. It then calculates a number of vectors equal to (x, y). Multiply.
Code
https://code.csdn.net/snippets/621864
bzoj-3505-number Triangle-cqoi2014