题解:P11063 【MX-X4-T3】「Jason-1」数对变换
注意到可以进行操作:
那么我们只需要令
其中我们要每次选择一个合适的
我们考虑观察函数,
的性质,我们使用 GeoGebra,易得:
容易发现,在取
具体的,我们令
考虑将函数性质带入最上面的迭代中。
注意到每次会减少略小于
这是真的吗?考虑特例!
-
+ 此时只有 $a=b=1$ 才会有解。 + 因为缩小是无法缩到上面图像描述的**看似**最小值的。 + 也就是说,我们在 $ab>1$ 的时候,永远无法缩到 $1$。 -
+ 注意到每次操作一定会使 $ab$ 减小。 + 那么,若 $ab<cd$ 一定无解,因为我们没法变大了。
否则,一定有解,按照上面的步骤求解即可,然后你会得到
int a, b, c, d;
vector<pair<int, int>> ans;
void work(int x, int y) {
ans.emplace_back(x, y);
if (x == 1) {
a /= y;
b *= y;
}
else {
b /= y;
a *= y;
}
}
void print() {
cout << ans.size() << endl;
for (auto t : ans)
cout << t.first << " " << t.second << endl;
}
int Main(int _) {
_ = _;
cin >> a >> b >> c >> d;
if (a * b < c * d)
return -1;
if (c * d == 1)
return (a * b == 1) - 1;
ans.clear(), work(1, a);
while (b >= 2 * c * d) {
int v = b / 2 + 1;
work(2, v);
work(1, v);
}
work(2, c * d);
work(1, d);
return print(), 1;
}
void Main() {
int T;
cin >> T;
while (T--) {
int res = Main(T);
if (res != 1)
cout << res << endl;
}
}
考虑优化。
容易发现我们两次操作才会进行一个有效的减小,这是很浪费的。
容易想到我们直接对着一个非
int Main(int _) {
_ = _;
cin >> a >> b >> c >> d;
if (a * b < c * d)
return -1;
if (c * d == 1)
return (a * b == 1) - 1;
ans.clear(), work(1, a);
while (a * b >= 2 * c * d) {
int v = a * b / 2 + 1;
if (a != 1)
work(1, v);
else
work(2, v);
}
if (a != 1)
work(1, a);
work(2, c * d);
work(1, d);
return print(), 1;
}