题解:P17202 DKM OI Round 1 - 小猫的考试
险些被出题组带走了。/ch
我们凭直觉考虑让一个点尽量晚一点被影响(进入循环),所以我们先把一个点设为
然后你发现这样子直到每个叶子都变成
可是非常不幸,这样恰好会在第 01010101... 就可以了。
Update on 2026.8.5:
由于赛场上着急过题用的乱搞,实际上可以正常一点。
扰动不需要直接给最后一个叶子加上,可以在这个叶子后面加一个扰动点,也设置为
::::success[乱搞]
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair <int, int> pii;
random_device rd;
mt19937 rnd (rd ());
// int rand(int l, int r)
// {
// return rnd () % (r - l + 1) + l;
// }
int n = 200000, a[200010];
vector <pii> v;
int main()
{
a[1] = 17;
int cur = 1;
for (int i = 1; i <= (1 << 17); i++)
{
for (int j = 0; j < a[i] && cur < n; j++)
{
a[++cur] = j;
v.push_back ({i, cur});
}
}
a[1 << 17] = 1;
for (int i = (1 << 17) + 1; i <= n; i++) a[i] = a[i - 1] ^ 1, v.push_back ({i - 1, i});
for (int i = 1; i <= n; i++) cout << a[i] << " ";
cout << "\n";
for (pii t : v) cout << t.x << " " << t.y << "\n";
return 0;
}
::::
::::success[正解]
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair <int, int> pii;
random_device rd;
mt19937 rnd (rd ());
// int rand(int l, int r)
// {
// return rnd () % (r - l + 1) + l;
// }
int n = 200000, a[200010];
vector <pii> v;
int main()
{
a[1] = 17;
int cur = 1;
for (int i = 1; i <= (1 << 17); i++)
{
for (int j = 0; j < a[i] && cur < n; j++)
{
a[++cur] = j;
v.push_back ({i, cur});
}
}
a[1 << 17] = 0;
a[(1 << 17) + 1] = 0;
v.push_back ({1 << 17, (1 << 17) + 1});
for (int i = (1 << 17) + 2; i <= n; i++) a[i] = 1, v.push_back ({1, i});
for (int i = 1; i <= n; i++) cout << a[i] << " ";
cout << "\n";
for (pii t : v) cout << t.x << " " << t.y << "\n";
return 0;
}
::::