Title Address: POJ 1265
Test instructions: Given a lattice polygon, find the internal number in, the number of points on the edge, and the area S.
Ideas: The use of a lot of theorems.
1. Pique theorem: s=in+on/2-1, i.e. in= (2*s+2-on)/2.
2. Polygon Area formula: The sum of the cross product of a vector consisting of two adjacent points and the origin is calculated sequentially.
3. Find the number of lattice points on the edge: a segment that is vertex-based, with points that are covered by GCD (Dx,dy), where Dxdy are the points in the horizontal segment and the points that are vertically accounted for. If DX or dy is 0, the number of points covered is dy or dx.
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map>using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const double pi= ACOs ( -1.0); const double esp=1e-6;int gcd (int a,int b) {while (b) {int r=b; B=a%b; A=r; } return A; int area (int x1,int y1,int x2,int y2) {return x1*y2-x2*y1;} int main () {int t,n,i; int dx,dy; int x1,y1,x2,y2; int icase=1; int in,on; Double S; scanf ("%d", &t); while (t--) {scanf ("%d", &n); x1=y1=x2=y2=0; in=on=s=0; while (n--) {scanf ("%d%d", &dx,&dy); The x2=x1+dx;//has two points consisting of a rectangular point y2=y1+dy; S+=area (X1,Y1,X2,Y2); ON+=GCD (ABS (DX), ABS (DY)); x1=x2; Y1=y2; } in= (s+2-on)/2; printf ("Scenario #%d:\n", icase++); printf ("%d%d%.1lf\n\n", in,on,s/2.0); } return 0;}
POJ 1265-area (Computational geometry + pique theorem + Polygon area formula)