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