P14001 [eJOI 2025] Prison の题解
什么 Steiner 三元环,不会,因此记录一下自己真实脑抽经历。
扯远一点,我在做下面提到的某道题甚至以为是模拟退火(啊不对,好像就是爬山)好题,果真一直在脑抽。
废物做法
我们大力观察,因为总要抠掉一个数,所以我们只能传递两个有效数字。
我们希望抠掉三个中的任意一个都能用一个二元组表示。
不妨设为知道其中两个就能表示出另外一个,根据某道题的观察,如果三个数的和一定,就能确定这个三元组,这里就设为
因为只有两个有效数字,我们就只看较小的两个。
我们再大力打表,发现似乎是
:::info[大力打表]
#pragma GCC optimize("Ofast", "inline", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
const int N = 1e6 + 10;
const int INF = 1e18;
const int MOD = 998244353;
using it2 = array<int, 2>;
const int m = 700;
signed main()
{
vector<it2> vec;
vec.reserve(3083817);
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < m; ++j)
{
int k = (m + m - i - j) % m;
int x = i, y = j, z = k;
if (x > y)
{
swap(x, y);
}
if (y > z)
{
swap(y, z);
}
if (x > y)
{
swap(x, y);
}
vec.push_back({x, y});
}
}
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
cout << vec.size() << '\n';
ofstream ouf("1.txt");
for (auto &[x, y] : vec)
{
ouf << x << ' ' << y << '\n';
}
return 0;
}
:::
并且观察输出,恰好就是
随手薅来一个
26 26
26 27
26 28
26 29
26 30
26 31
26 32
26 33
26 34
26 35
26 36
26 37
26 75
26 76
26 77
26 78
26 79
26 80
26 81
26 82
26 83
26 84
26 85
26 86
26 87
发现是一段区间,那么我们用
类似的,我们记
我们直接硬打表,每一个
我们在看看
例如如果
正经做法
你就当我上面在脑抽一小时(真的一小时),但是我们已经摸到一点门道了。
然后我一拍脑袋,发现其实可以在 setup 里面提前打好表的,让我累死了。
#include <bits/stdc++.h>
using namespace std;
const int N = 31e5;
const int M = 4300;
int a[M][M];
vector<int> vec[N];
int setup(int m)
{
int cnt = 0;
for (int i = 0; i < m; ++i)
{
for (int j = i; j < m; ++j)
{
int k = (m + m - i - j) % m;
if (j <= k)
{
vec[cnt] = {i, j, k};
a[i][j] = a[j][k] = a[k][i] = a[j][i] = a[k][j] = a[i][k] = cnt++;
}
}
}
return cnt;
}
vector<int> encode(int n)
{
return vec[n];
}
int decode(int x, int y)
{
return a[x][y];
}