皮克公式:求格点多边形面积
A=B2+I−1A=\frac B 2+I-1 A=2B+I−1
其中
A:area 面积
B:boundary 边界上整点的个数
I:interior 多边形内部点的个数
对于两个整数点(x1,y1),(x2,y2)(x_1,y_1),(x_2,y_2)(x1,y1),(x2,y2)来说,它们连线上整点的个数为gcd(x2−x1,y2−y1)\gcd(x_2-x_1,y_2-y_1)gcd(x2−x1,y2−y1)
考虑下面的式子2A=B+2(I−1)2A=B+2(I-1)2A=B+2(I−1)
对于本题来说,首先由于点的坐标都是偶数,那么任意三点组成的三角形面积一定是偶数,并且由题意得满足条件时III为奇数,那么2(i−1)2(i-1)2(i−1)一定时4的倍数,同时2A2A2A也是4的倍数,可以推出B是4的倍数是满足题意的充分必要条件!
由于点的坐标都是偶数点,那么gcd(x2−x1,y2−y1)[mod4\gcd(x_2-x_1,y_2-y_1)[\mod4gcd(x2−x1,y2−y1)[mod4]只有两种情况即000或者222。
gcd(x2−x1,y2−y1)≡{0,x1≡x2(mod4)andy1≡y2(mod4)2,else\gcd(x_2-x_1,y_2-y_1)\equiv \begin{cases}0,x_1\equiv x_2\pmod4 \text{and} y_1 \equiv y_2\pmod4\\2,\text{else} \end{cases}gcd(x2−x1,y2−y1)≡{0,x1≡x2(mod4)andy1≡y2(mod4)2,else
太晚了懒得写了,放的dls的代码p\color{black}\text ppreehs_moorhsum\color{red}\text {reehs\_moorhsum}reehs_moorhsum
#include <bits/stdc++.h>using namespace std;
using ll=long long;
const int maxn=7005;int n, x[maxn], y[maxn];
int cnt[10][10], d[maxn][maxn];
ll ans;
pair<int,int> g[maxn];
int main() {scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d%d", x + i, y + i);cnt[x[i] % 4][y[i] % 4]++;g[i] = make_pair(x[i] % 4, y[i] % 4);}vector<pair<int,int>> p{{0, 0}, {0, 2}, {2, 0}, {2, 2}};for (auto x : p)for (auto y : p)for (auto z : p)if (x <= y && y <= z) {int d1 = (x == y) ? 0 : 2, d2 = (y == z) ? 0 : 2,d3 = (x == z) ? 0 : 2;int c1 = cnt[x.first][x.second], c2 = cnt[y.first][y.second], c3 = cnt[z.first][z.second];if ((d1 + d2 + d3) % 4 == 0) {if (x == y && y == z) {ans += (ll)c1 * (c1 - 1) * (c1 - 2) / 6;} else if (x == y) {ans += (ll)c1 * (c1 - 1) / 2 * c3;} else if (y == z) {ans += (ll)c1 * c3 * (c3 - 1) / 2;} else {ans += (ll)c1 * c2 * c3;}}}printf("%lld\n", ans);/* for (int i = 1; i <= n; i++)for (int j = i + 1; j <= n; j++)d[i][j] = abs(__gcd(x[i] - x[j], y[i] - y[j]));int ans2 = 0;for (int i = 1; i <= n; i++)for (int j = i + 1; j <= n; j++)for (int k = j + 1; k <= n; k++) {assert(((d[i][j] + d[j][k] + d[i][k]) % 4 == 0) ==(g[i] == g[j] || g[j] == g[k] || g[k] == g[i]));if ((d[i][j] + d[j][k] + d[i][k]) % 4 == 0) {ans2++;}}printf("%d\n", ans2);*/
}