bzoj-3505-number Triangle-cqoi2014

Source: Internet
Author: User
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

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.