题意:
给定n组数据:每组数据代表一个点,保证点的坐标为整数,求选三个点构成的三角形的面积是整数并且三角形内整点个数是奇数的选法数量
思路:
一开始很茫然,然后看到了pick定理:
假设有三个点A:(x1,y1)
,B:(x2,y2)
,C:(x3,y3)
,我们通过向量计算面积:
由于这六个数字都为偶数,则说明S能被2除尽。所以在easy难度里,面积一定为偶数
对于pick定理:对于左右乘以二:得到2A=2i+b-2
,由于内部格点数目i为奇数,所以2i
能被2除尽但不能被4除尽,2i-2
能被4除尽,S也能被4除尽,所以只要保证b为4的倍数即可
两点坐标上的点的坐标为整数的个数为gcd(|x2-x1|,|y2-y1|)
因为节点的值都是偶数,所以该值mod4之后只有两种答案:0或者2
找到mod4为0的答案就行了
//Author:Happy Dog
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=7005;
int n, x[7007],y[7007];
int cnt[10][10],d[7007][7007];
ll ans;
pair<int,int> g[maxn];
int main()
{
cin>>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);
}