QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#9075. 位反转

统计

给定两个整数 $x$ 和 $y$,你可以花费一枚硬币,将任意数字二进制表示中的任意连续三位进行反转(可以包含前导零)。反转 $(1, 2, 3)$ 意味着将其变为 $(3, 2, 1)$。

请找出一种方法,使得花费的硬币数量最少,从而将 $x$ 变为 $y$。如果可以实现,请输出所需的最少硬币数量;否则,输出 -1。

输入格式

输入文件的第一行包含一个整数 $T$ ($1 \le T \le 10000$),表示测试用例的数量。 接下来有 $T$ 行,每行代表一个测试用例。 对于每个测试用例,包含两个整数 $x, y$ ($0 \le x, y \le 10^{18}$),含义如上所述。

输出格式

请准确输出 $T$ 行。 对于每一行,首先输出 Case d:($d$ 表示测试用例的编号),然后输出答案。如果无法实现,则输出 -1。

样例

样例输入 1

3
0 3
3 6
6 9

样例输出 1

Case 1: -1
Case 2: 1
Case 3: 2

说明

  • 样例 1:考虑以下两个二进制字符串: $0: 0 \cdots 0000$ $3: 0 \cdots 0011$ 无法达到目标。

  • 样例 2:考虑以下两个二进制字符串: $3: 0 \cdots 0011$ $6: 0 \cdots 0110$ 你可以反转 $3$ 的最低三位,使得 $3$ 变为 $6$。 你只需要执行一次反转,因此所需的最少硬币数量为 1。

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.