The main idea: start with the origin and then add an x, Y value each time, find out how many points at the end of the polygon edge, how many internal points, polygon area is how much.
Analysis:
1, with the lattice point as the vertex of the line segment, the number of points covered is gcd (Dx,dy), wherein, dxdy respectively for the segment of the horizontal and vertical points accounted for. If DX or dy is 0, the number of points covered is dy or dx.
2. 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.
3. The area of any polygon is equal to the sum of the cross product of the vector of two neighboring points and the origin in order.
The code is as follows:
-------------------------------------------------------------------------------------------------------------
#include <iostream>#include<string.h>#include<stdio.h>#include<algorithm>#include<math.h>using namespacestd;Const intMAXN = 1e4+7;Const DoubleEPS = 1e-Ten;intGCD (intMintN) { if(!m | |!N)returnm+N; returnGCD (N, m%n);}intMain () {intT, t=1; scanf ("%d", &T); while(t--) { intN, x, Y, nx=0, ny=0, cnt=0, area=0; scanf ("%d", &N); for(intI=0; i<n; i++) {scanf ("%d%d", &x, &y); CNT+=GCD (ABS (x), ABS (y)); X+ = NX, y + =NY; Area+ = (x*ny-y*NX); NX= x, NY =y; } if(Area <0) area =-Area ; printf ("Scenario #%d:\n", t++); printf ("%d%d%.1f\n\n", (AREA-CNT)/2+1, CNT, area/2.0); } return 0;}
Area-poj 1265 (pick theorem to find lattice points + polygon area)