POJ 1265 (pick定理 + 多边形面积)
作者:互联网
题目:传送门
题意:一个点最初在(0, 0),给你它的运动轨迹,保证是一个多边形,问你这个多边形边界上的格点个数以及多边形内部的格点个数和多边形的面积。
思路: pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <queue> #include <map> #include <vector> #include <set> #include <string> #include <math.h> #define LL long long #define mem(i, j) memset(i, j, sizeof(i)) #define rep(i, j, k) for(int i = j; i <= k; i++) #define dep(i, j, k) for(int i = k; i >= j; i--) #define pb push_back #define make make_pair #define INF INT_MAX #define inf LLONG_MAX #define PI acos(-1) #define fir first #define sec second using namespace std; const int N = 1e6 + 5; int a[N]; int Cas = 0, n; int x = 0, y = 0, addx, addy, nx, ny; int Point_in, Point_on = 0; double s = 0; void solve() { scanf("%d", &n); s = 0; x = 0; y = 0; Point_on = 0; rep(i, 1, n) { scanf("%d %d", &addx, &addy); nx = x + addx; ny = y + addy; Point_on += __gcd(abs(addx), abs(addy)); s += (x * ny - y * nx); x = nx; y = ny; } if(s < 0) s = -s; Point_in = (s - Point_on + 2) / 2; printf("Scenario #%d:\n%d %d %.1f\n\n",++Cas,Point_in,Point_on,s/2.0); } int main() { int _; scanf("%d", &_); while(_--) solve(); // solve(); return 0; }
标签:多边形,Point,int,1265,ny,POJ,pick,include,define 来源: https://www.cnblogs.com/Willems/p/12442081.html