QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 1024 MB 總分: 100 难度: [顯示] 可 Hack ✓

#8058. 二进制与三进制

统计

二进制字符串是由位(即“0”和“1”)组成的序列。对于一个二进制字符串 $S$,你可以执行任意次数的以下操作:

  • 选择一个非空子串 $S[l, r] = S_l S_{l+1} \dots S_r$,将其视为一个三进制(即基数为 3)整数,然后将其转换为对应的二进制整数。例如,$(101)_3 = (1010)_2$,因此你可以将 $110110$ 转换为 $1101010$。

注意,所选的子串可能包含前导零,但转换后的子串将不会有前导零。我们将 $0$ 视为一个没有前导零的合法二进制整数。例如,你可以将 $01$ 转换为 $1$,因为 $(01)_3 = (1)_2$。你也可以将 $0$ 转换为 $0$,因为 $(0)_3 = (0)_2$。

给定两个均以数字“1”开头的二进制字符串 $A$ 和 $B$,你需要确定 $A$ 是否能在不超过 $512$ 次操作内转换为 $B$。并且在转换过程中,字符串的长度不能超过 $128$。如果可能,请输出一种方案。

输入格式

输入文件包含多个测试用例。第一行包含一个整数 $T$ ($1 \le T \le 1000$),表示测试用例的数量。

对于每个测试用例,第一行包含字符串 $A$ ($1 \le |A| \le 64$)。第二行包含字符串 $B$ ($1 \le |B| \le 64$)。

保证 $A$ 和 $B$ 都以数字“1”开头,且仅由“1”和“0”组成。

输出格式

对于每个测试用例,如果无法将字符串 $A$ 转换为 $B$,输出“-1”。

否则,首先输出一个整数 $n$ ($0 \le n \le 512$),表示操作步数。在接下来的 $n$ 行中,每行输出两个整数 $l, r$ ($1 \le l \le r$),表示你在每一步中选择的子串。索引从 1 开始。$r$ 不应超过当前字符串的长度。

样例

输入 1

3
1
111
110110
1101010
1111
111111

输出 1

-1
1
2 4
2
1 3
2 5

说明

在第一个测试用例中,可以证明不存在可能的解决方案。

在第二个测试用例中,对于 $A = 110110$,我们可以先选择 $l = 2$ 和 $r = 4$。由于 $A[2, 4] = 101$,且 $(101)_3 = (1010)_2$,因此 $110110$ 将变为 $1101010$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.