Pick Formula: The area of a simple polygon with a lattice point on a plane = the number of points on the edge/2+ the number of points inside +1.
The code is as follows:
--------------------------------------------------------------------------------------------------------------- -------------
#include <iostream>#include<string.h>#include<stdio.h>#include<algorithm>#include<math.h>using namespacestd;Const intMAXN = -;Const DoubleEPS = 1e-Ten;structpoint{intx, y;} P[MAXN];intGCD (intMintN) { if(!m | |!N)returnm+N; returnGCD (N, m%n);}intMain () { while(1) { intok=0; for(intI=0; i<3; i++) {scanf ("%d%d", &p[i].x, &p[i].y); if(p[i].x | |p[i].y) OK=1; } if(!ok) Break; p[3] = p[0]; intCnt=0, area=0; for(intI=0; i<3; i++) {CNT+ = GCD (ABS (p[i].x-p[i+1].x), ABS (p[i].y-p[i+1].y)); Area+ = p[i].x*p[i+1].y-p[i].y*p[i+1].x; } if(Area <0) area =-Area ; printf ("%d\n", (AREA-CNT)/2+1); } return 0;}
Triangle-poj 2954 (Find the number of lattice points within the triangle)