皮克定理:$2S=2a+b-2$
S为多边形面积,a为多边形内部的点数,b为多边形上的点数
模板题:https://vjudge.net/problem/Gym-101873G
先用叉积求出多边形的面积S,然后再计算多边形上经过的整数点个数$b,a=(2S-b+2)/2$
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 1e5+110; struct Node { ll x,y; }node[maxn]; ll cal(int a,int b,int c) { return (node[a].x-node[b].x)*(node[b].y-node[c].y)-(node[b].x-node[c].x)*(node[a].y-node[b].y); } ll cal2(int a,int b) { ll x=abs(node[a].x-node[b].x); ll y=abs(node[a].y-node[b].y); return __gcd(x,y); } int main() { int n; ll b=0,S=0; cin>>n; for(int i=1;i<=n;i++) scanf("%lld %lld",&node[i].x,&node[i].y); for(int i=3;i<=n;i++) S+=cal(1,i-1,i); for(int i=2;i<=n;i++) b+=cal2(i,i-1); b+=cal2(n,1); cout<<(abs(S)-b+2)/2<<endl; return 0; }