哎这怎么是计算几何?
题目 Hoof, Paper, Scissors Triples 来源 USACO 2026 First Contest, Platinum。
在“蹄子剪刀布”游戏中,蹄子胜剪刀,剪刀胜布,布胜蹄子。现在有
首先,合法的三元组
计算可得,奶牛
那么,奶牛
发现不等式左侧各项系数和结构比较对称。考虑引入三次单位根
条件可以转化为
或者忽略不影响符号的常系数记平面向量
因此原问题等价于求三元组
考虑反过来统计不合法的三元组。可以证明,
因此,考虑将
然而,当辐角正好相差
注意到当
最后,答案就是总数
当然,其实
:::info[代码]
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::vector<std::pair<long long, long long>> b;
for (int i = 0; i < n; i++) {
int x, y, z;
std::cin >> x >> y >> z;
if (x * 2 - y - z != 0 || y - z != 0) {
int u = x * 2 - y - z;
int v = y - z;
int w = std::abs(std::__gcd(u, v));
b.emplace_back(u / w, v / w);
}
}
n = b.size();
std::sort(b.begin(), b.end(), [](const std::pair<long long, long long> &x, const std::pair<long long, long long> &y) -> bool {
int fx = x.second == 0 ? (x.first > 0 ? 0 : 1) : (x.second > 0 ? 0 : 1);
int fy = y.second == 0 ? (y.first > 0 ? 0 : 1) : (y.second > 0 ? 0 : 1);
if (fx != fy)
return fx < fy;
return x.second * y.first < y.second * x.first;
});
long long res = (long long)n * (n - 1) * (n - 2) / 6;
for (int i = 0, j = 0; i < n; i++) {
while (j < n + i && (j < n || b[j % n] != b[i]) && b[j % n].second * b[i].first - b[j % n].first * b[i].second >= 0)
j++;
res -= (long long)(j - i - 1) * (j - i - 2) / 2;
}
for (int i = 0, j = 0, k = 0; i < n; i = j) {
while (j < n && b[i] == b[j])
j++;
k = std::max(k, j);
while (k < n && b[k].second * b[i].first - b[k].first * b[i].second > 0)
k++;
if (k < n && b[k].second * b[i].first - b[k].first * b[i].second == 0) {
int l = k;
while (l < n && b[k] == b[l])
l++;
res += (long long)(j - i) * (l - k) * (j - i + l - k - 2) / 2;
}
}
std::cout << res << '\n';
}
return 0;
}
:::