皮克公式:求格点多边形面积
A
=
B
2
+
I
−
1
A=\frac B 2+I-1
A=2B+I−1
其中
A:area 面积
B:boundary 边界上整点的个数
I:interior 多边形内部点的个数
对于两个整数点 ( x 1 , y 1 ) , ( x 2 , y 2 ) (x_1,y_1),(x_2,y_2) (x1,y1),(x2,y2)来说,它们连线上整点的个数为 gcd ( x 2 − x 1 , y 2 − y 1 ) \gcd(x_2-x_1,y_2-y_1) gcd(x2−x1,y2−y1)
考虑下面的式子
2
A
=
B
+
2
(
I
−
1
)
2A=B+2(I-1)
2A=B+2(I−1)
对于本题来说,首先由于点的坐标都是偶数,那么任意三点组成的三角形面积一定是偶数,并且由题意得满足条件时
I
I
I为奇数,那么
2
(
i
−
1
)
2(i-1)
2(i−1)一定时4的倍数,同时
2
A
2A
2A也是4的倍数,可以推出B是4的倍数是满足题意的充分必要条件!
由于点的坐标都是偶数点,那么 gcd ( x 2 − x 1 , y 2 − y 1 ) [ m o d 4 \gcd(x_2-x_1,y_2-y_1)[\mod4 gcd(x2−x1,y2−y1)[mod4]只有两种情况即 0 0 0或者 2 2 2。
gcd ( x 2 − x 1 , y 2 − y 1 ) ≡ { 0 , x 1 ≡ x 2 ( m o d 4 ) and y 1 ≡ y 2 ( m o d 4 ) 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 p p reehs_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);*/
}