CF2157F 题解
考虑将不同的技能值
运用二进制思想,在第
尝试减少提升轮数。类似的,考虑对
在第一轮操作,顺序枚举整数
完成第一轮操作后,所有非
上述过程总代价约为
:::info[Code]
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
using pii = pair<int, int>;
constexpr int B = 64;
int n;
vector<pair<int, int>> e;
void step(int x) {
rep(p, 1, B - 1) {
if (p * x > n) break;
int k = p * x;
while (k + x * B <= n) {
k += x * B;
}
for (int i = k; i >= 1; i -= x * B) {
e.push_back({i, x});
}
}
}
int main() {
cin >> n;
step(1), step(B), step(B * B);
// 三轮操作足以将所有数移到 B*B*B,取 B = 64 时大于 250000.
cout << e.size() << endl;
for (auto p : e) {
cout << p.first << " " << p.second << endl;
}
}
:::