area:http://poj.org/problem?id=1265
To give you a point of the horizontal ordinate change value, ask how many points in the polygon, how many points in the polygon, and the area of the polygon.
Idea: Pick theorem.
A polygon area formula for calculating vertices at lattice points in a lattice: s=a+b÷2-1, where a represents the number of points within the Polygon, B represents the number of points on the polygon boundary, and S represents the area of the polygon.
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
#include <map> #include <stack> #include <queue> #include <math.h> #include <stdio.h> #inc Lude <stdlib.h> #include <string.h> #include <iostream> #include <limits.h> #include < Algorithm> #define LL long #define MAX (A,B) ((a) > (b)? ( A):(b) #define MIN (a,b) ((a) < (b)? ( A):(B) #define MAX3 (A, B, c) (A>b?max (A, C): Max (b, c)) #define MIN3 (A, B, c) (A<b?min (A, c): Min (b, c)) #define Max4 (A, B, C, D) Max (Max (A, B), Max (C, D)) #define MIN4 (A, B, C, D) min (min (A, b), Min (c, D)) #define EPS 1e-9 #define INF 1 &
lt;< using namespace std;
int T, n;
int cnt, Ans, A, B; struct point {int x, y;}
N[105];
int area (Point A, point B) {return a.x*b.y-a.y*b.x;}
int gcd (int a, int b) {if (b = = 0) {return A;
else {return gcd (b, a%b);
} void Solve () {int T;
scanf ("%d", &t);
for (int p = 1; p <= T; ++p) {scanf ("%d", &n); Ans = CNT = n[0].x = N[0].Y = 0;
for (int i = 1; I <= n; ++i) {scanf ("%d%d", &a, &b);
n[i].x = N[i-1].x+a;
N[i].y = n[i-1].y+b;
Ans + + area (N[i], n[i-1]);
CNT + + GCD (ABS (a), ABS (b));
Ans = abs (ans);
printf ("Scenario #%d:\n", p);
printf ("%d%d%.1lf\n\n", (ans-cnt+2)/2, CNT, ans*0.5);
int main (void) {freopen ("data.in", "R", stdin);
Freopen ("Data.out", "w", stdout);
Solve ();
return 0; } area