这道题就是计算三角形里面的格点的个数, 可以用匹克定理, s = n + b/2 - 1; 其中s是格点多边形的面积, n是多边形内部的格点数目, b是边界上的格点,假设有两个坐标(x1, y1) (x2, y2) b = gcd(abs(x1-x2), (y1-y2)).代码如下:
/* ID: m1500293 LANG: C++ PROG: fence9 */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n, m, p; struct Point { int x, y; Point() {} Point(int x, int y):x(x), y(y) {} }; int getarea(Point AB, Point AC) { return abs((AB.x*AC.y-AB.y*AC.x)/2); } int gcd(int m, int n) { if(n == 0) return m; else return gcd(n, m%n); } int main() { freopen("fence9.in", "r", stdin); freopen("fence9.out", "w", stdout); scanf("%d%d%d", &n, &m, &p); Point AB(n, m), AC(p, 0); int SA = getarea(AB, AC); int b = gcd(n, m) + gcd(p, 0) + gcd(abs(n-p), m); int res = SA + 1 - b/2; printf("%d ", res); return 0; }