跳到正文

题解

题解:P11063 【MX-X4-T3】「Jason-1」数对变换

RainPPR约 4 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 4 分钟
题目
P11063

版本

  1. v1当前

注意到可以进行操作:

(1,t) 2 cd →(cd,⌊tcd⌋) 1 d →(c,d⌊tcd⌋)\def\op#1#2{\underrightarrow{\scriptsize\texttt{ #1 #2 }}} \def\floor#1{\left\lfloor{#1}\right\rfloor} (1,t)\op2{cd}\left(cd,\floor{\dfrac t{cd}}\right)\op1{d}\left(c,d\floor{\dfrac t{cd}}\right)

那么我们只需要令 cd≤t<2cdcd\le t<2cd 即可结束,于是考虑构造。

(a,b) 1 a →(1,ab) 2 k →(k,⌊abk⌋) 1 k →(1,k⌊abk⌋)\def\op#1#2{\underrightarrow{\scriptsize\texttt{ #1 #2 }}} \def\floor#1{\left\lfloor{#1}\right\rfloor} (a,b)\op1{a}(1,ab)\op2{k}\left(k,\floor{\dfrac{ab}k}\right)\op1{k}\left(1,k\floor{\dfrac{ab}k}\right)

其中我们要每次选择一个合适的 kk,使得最终落到要求区间即可。


我们考虑观察函数,

f(x)=x⌊ax⌋,a=const.\def\floor#1{\left\lfloor{#1}\right\rfloor} f(x)=x\floor{\dfrac ax},a=\text{const.}

的性质,我们使用 GeoGebra,易得:

容易发现,在取 x=a/2x=a/2 附近的时候,可以取到最小值 a/2a/2 左右。

具体的,我们令 x=⌊a/2⌋+1x=\lfloor a/2\rfloor+1 的时候,可以取到整数时的最小值!


考虑将函数性质带入最上面的迭代中。

注意到每次会减少略小于 ab/2ab/2 的大小,这意味着我们 一定 可以取到目标区间。

这是真的吗?考虑特例!

  • c=d=1c=d=1:

    • 此时只有 a=b=1a=b=1 才会有解。

    • 因为缩小是无法缩到上面图像描述的看似最小值的。

    • 也就是说,我们在 ab>1ab>1 的时候,永远无法缩到 11。

  • ab<cdab<cd:

    • 注意到每次操作一定会使 abab 减小。

    • 那么,若 ab<cdab<cd 一定无解,因为我们没法变大了。

否则,一定有解,按照上面的步骤求解即可,然后你会得到 50pts50\text{pts} 做法。

C++
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;
	}
}

考虑优化。

容易发现我们两次操作才会进行一个有效的减小,这是很浪费的。

容易想到我们直接对着一个非 11 的消去,否则消另外一个即可,代码:

C++
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;
}
原文