Usaco Electric Fence

Source: Internet
Author: User
Tags gcd

The problem is to calculate the number of lattice points inside the triangle, you can use the peak theorem, s = n + b/2-1; where S is the area of the lattice polygon, n is the number of lattice points inside the polygon, and B is the lattice point on the boundary, assuming there are two coordinates (x1, y1) (x2, y2) b = gcd (ABS (X1-X2), (Y1-y2)). The code is as follows:

/*id:m1500293 lang:c++ Prog:fence9*/#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;intN, M, p;structpoint{intx, y; Point () {}, point (intXinty): x (x), Y (y) {}};intGetarea (Point AB, point AC) {returnABS ((ab.x*ac.y-ab.y*ac.x)/2);}intgcdintMintN) {    if(n = =0)returnm; Else returnGCD (N, m%n);}intMain () {Freopen ("fence9.in","R", stdin); Freopen ("Fence9.out","W", stdout); scanf ("%d%d%d", &n, &m, &p); Point AB (N, m), AC (p,0); intSA =Getarea (AB, AC); intb = gcd (n, m) + GCD (p,0) + GCD (ABS (np), m); intres = SA +1-B/2; printf ("%d\n", RES); return 0;}

Usaco Electric Fence

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.