皮克定理用于计算点阵中顶点在格点上的多边形面积。对于一个顶点全部在格点上的多边形来说,它的面积计算有如下特点:
如果用a表示位于多边形内部的格点数,b表示位于多边形边界上的格点数,则多边形面积可表示为S = a + b/2 – 1 .
皮克定理用于计算点阵中顶点在格点上的多边形面积。对于一个顶点全部在格点上的多边形来说,它的面积计算有如下特点:
如果用a表示位于多边形内部的格点数,b表示位于多边形边界上的格点数,则多边形面积可表示为S = a + b/2 – 1 .
InputThe input test file will contain multiple test cases. Each input test case consists of six integers x1, y1, x2, y2, x3, and y3, where (x1, y1), (x2, y2), and (x3, y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and -15000 ≤ x1, y1, x2, y2, x3, y3 ≤ 15000. The end-of-file is marked by a test case with x1 = y1 = x2 = y2 = x3 = y3 = 0 and should not be processed.
OutputFor each input case, the program should print the number of internal lattice points on a single line.Sample Input
0 0 1 0 0 1 0 0 5 0 0 5 0 0 0 0 0 0
Sample Output
0 6
所以直接叉积算面积,点的话可以gcd,so easy
#include<bits/stdc++.h> using namespace std; #define x first #define y second pair<int,int>P[3],M[3]; int main() { while(cin>>P[0].x>>P[0].y>>P[1].x>>P[1].y>>P[2].x>>P[2].y) { if(!P[0].x&&!P[0].y&&!P[1].x&&!P[1].y&&!P[2].x&&!P[2].y)break; int sum=abs((P[1].x-P[0].x)*(P[2].y-P[0].y)-(P[1].y-P[0].y)*(P[2].x-P[0].x)); for(int i=0;i<3;i++) M[i].x=abs(P[i].x-P[i-1<0?i+2:i-1].x),M[i].y=abs(P[i].y-P[i-1<0?i+2:i-1].y),sum-=__gcd(M[i].x,M[i].y); cout<<sum/2+1<<" "; } }
友情放送多边形重心(也可以求面积,取abs就好了),这篇博客的C