欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2138A.Cake Assignment
Cake Assignment
Chocola and Vanilla love cakes. Today, the manager of a cake shop gave them a total of cakes. The cakes were distributed evenly, so each of them initially received cakes.
However, Chocola and Vanilla now want to redistribute the cakes such that Chocola ends up with exactly cakes and Vanilla gets the remaining cakes.
In one step, they can perform exactly one of the following two operations:
- Chocola gives half of her cakes to Vanilla. This operation is only allowed if Chocola currently has an even number of cakes.
- Vanilla gives half of her cakes to Chocola. This operation is only allowed if Vanilla currently has an even number of cakes.
Your task is to determine the minimum number of steps required to reach the target distribution and to output any valid sequence of operations achieving that minimum.
It can be proven that, under the given constraints, a valid solution always exists, and the minimum number of steps required is at most .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and (, ) — each person initially received cakes, and is the number of cakes Chocola should have after redistribution.
Output
For each test case, output a single integer () representing the minimum number of steps required for them to redistribute the cakes accordingly.
On the next line, output integers ( or ), where means that in the -th step, Chocola gave half of her cakes to Vanilla (operation 1), and means that Vanilla gave half of her cakes to Chocola (operation 2).
Note
In the first test case, they can use the following steps so that Chocola has exactly cakes and Vanilla has exactly cakes. We use to denote that Chocola currently has cakes and Vanilla currently has cakes.
$$$\{4, 4\} \xrightarrow{o_1 = \mathtt{2}} \{6, 2\} \xrightarrow{o_2 = \mathtt{1}} \{3, 5\}$$</p><p>In the second test case, Chocola already has exactly$x = 4$cakes and Vanilla already has exactly$2 ^ {k + 1} - x = 4$cakes, so no operations are required.</p><p>In the third test case, they can use the following steps so that Chocola has exactly$x = 7$cakes and Vanilla has exactly$2 ^ {k + 1} - x = 9$cakes.</p><p>$$\{8, 8\} \xrightarrow{o_1 = \mathtt{2}} \{12, 4\} \xrightarrow{o_2 = \mathtt{2}} \{14, 2\} \xrightarrow{o_3 = \mathtt{1}} \{7, 9\}$$$Samples
4
2 3
2 4
3 7
2 5
2
2 1
0
3
2 2 1
2
1 2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |