310149: CF1789D. Serval and Shift-Shift-Shift

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Serval and Shift-Shift-Shift

题意翻译

给你两个 $n$ 位二进制数 $a$ 和 $b$。 你需要执行若干次以下操作(可以为零)来使得 $a$ 和 $b$ 相等: + 选择一个正整数 $k$,然后令 $a \oplus (a ≪ k)$ 或 $a \oplus (a ≫ k)$。 换句话说,你每次可以令 $a$ 左移 $k$ 位或右移 $k$ 位,溢出的位被移除,缺失的位被补 $0$,然后异或上左移/右移前的 $a$。 若不可能在 $n$ 次操作内使得 $a=b$,输出 $-1$,否则输出具体操作方案(不用最小化步数)。 Translated by [Tx_Lcy](https://www.luogu.com.cn/user/253608)

题目描述

Serval has two $ n $ -bit binary integer numbers $ a $ and $ b $ . He wants to share those numbers with Toxel. Since Toxel likes the number $ b $ more, Serval decides to change $ a $ into $ b $ by some (possibly zero) operations. In an operation, Serval can choose any positive integer $ k $ between $ 1 $ and $ n $ , and change $ a $ into one of the following number: - $ a\oplus(a\ll k) $ - $ a\oplus(a\gg k) $ In other words, the operation moves every bit of $ a $ left or right by $ k $ positions, where the overflowed bits are removed, and the missing bits are padded with $ 0 $ . The bitwise XOR of the shift result and the original $ a $ is assigned back to $ a $ . Serval does not have much time. He wants to perform no more than $ n $ operations to change $ a $ into $ b $ . Please help him to find out an operation sequence, or determine that it is impossible to change $ a $ into $ b $ in at most $ n $ operations. You do not need to minimize the number of operations. In this problem, $ x\oplus y $ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of $ x $ and $ y $ . $ a\ll k $ and $ a\gg k $ denote the [logical left shift](https://en.wikipedia.org/wiki/Logical_shift) and [logical right shift](https://en.wikipedia.org/wiki/Logical_shift).

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1\le t\le2\cdot10^{3} $ ). The description of the test cases follows. The first line of each test case contains a single integer $ n $ ( $ 1\le n\le2\cdot10^{3} $ ) — the number of bits in numbers $ a $ and $ b $ . The second and the third line of each test case contain a binary string of length $ n $ , representing $ a $ and $ b $ , respectively. The strings contain only characters 0 and 1. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2\cdot10^{3} $ .

输出格式


For each test case, if it is impossible to change $ a $ into $ b $ in at most $ n $ operations, print a single integer $ -1 $ . Otherwise, in the first line, print the number of operations $ m $ ( $ 0\le m\le n $ ). If $ m>0 $ , in the second line, print $ m $ integers $ k_{1},k_{2},\dots,k_{m} $ representing the operations. If $ 1\le k_{i}\le n $ , it means logical left shift $ a $ by $ k_{i} $ positions. If $ -n\le k_{i}\le-1 $ , it means logical right shift $ a $ by $ -k_{i} $ positions. If there are multiple solutions, print any of them.

输入输出样例

输入样例 #1

3
5
00111
11000
1
1
1
3
001
000

输出样例 #1

2
3 -2
0
-1

说明

In the first test case: The first operation changes $ a $ into $ 00111\oplus\sout{001}11\underline{000}=11111 $ . The second operation changes $ a $ into $ 11111\oplus\underline{00}111\sout{11}=11000 $ . The bits with strikethroughs are overflowed bits that are removed. The bits with underline are padded bits. In the second test case, $ a $ is already equal to $ b $ , so no operations are needed. In the third test case, it can be shown that $ a $ cannot be changed into $ b $ .

Input

题意翻译

给你两个 $n$ 位二进制数 $a$ 和 $b$。 你需要执行若干次以下操作(可以为零)来使得 $a$ 和 $b$ 相等: + 选择一个正整数 $k$,然后令 $a \oplus (a ≪ k)$ 或 $a \oplus (a ≫ k)$。 换句话说,你每次可以令 $a$ 左移 $k$ 位或右移 $k$ 位,溢出的位被移除,缺失的位被补 $0$,然后异或上左移/右移前的 $a$。 若不可能在 $n$ 次操作内使得 $a=b$,输出 $-1$,否则输出具体操作方案(不用最小化步数)。 Translated by [Tx_Lcy](https://www.luogu.com.cn/user/253608)

Output

**标题:Serval 和 Shift-Shift-Shift**

**题意翻译:**
给定两个 $n$ 位的二进制数 $a$ 和 $b$。通过执行以下操作(可以为零次)来使得 $a$ 和 $b$ 相等:

选择一个正整数 $k$,然后执行 $a \oplus (a \ll k)$ 或 $a \oplus (a \gg k)$。

换句话说,每次可以将 $a$ 左移 $k$ 位或右移 $k$ 位,溢出的位被移除,缺失的位补 $0$,然后异或上左移/右移前的 $a$。

若不可能在 $n$ 次操作内使得 $a=b$,输出 $-1$,否则输出具体操作方案(不用最小化步数)。

**题目描述:**
Serval 有两个 $n$ 位二进制整数 $a$ 和 $b$,他想把这两个数字分享给 Toxel。因为 Toxel 更喜欢数字 $b$,所以 Serval 决定通过一些操作(可能为零次)将 $a$ 变为 $b$。在每次操作中,Serval 可以选择任意一个正整数 $k$($1 \leq k \leq n$),并按照以下任一方式改变 $a$:

- $a \oplus (a \ll k)$
- $a \oplus (a \gg k)$

换句话说,这个操作将 $a$ 的每一位左移或右移 $k$ 位,其中溢出的位被移除,缺失的位用 $0$ 填充。将移位结果与原始 $a$ 的按位异或结果赋值给 $a$。

Serval 没有太多时间。他希望最多进行 $n$ 次操作将 $a$ 变为 $b$。请帮助他找出一个操作序列,或者确定无法在最多 $n$ 次操作内将 $a$ 变为 $b$。你不需要最小化操作次数。

在这个问题中,$x \oplus y$ 表示 $x$ 和 $y$ 的[按位异或操作](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)。$a \ll k$ 和 $**标题:Serval 和 Shift-Shift-Shift** **题意翻译:** 给定两个 $n$ 位的二进制数 $a$ 和 $b$。通过执行以下操作(可以为零次)来使得 $a$ 和 $b$ 相等: 选择一个正整数 $k$,然后执行 $a \oplus (a \ll k)$ 或 $a \oplus (a \gg k)$。 换句话说,每次可以将 $a$ 左移 $k$ 位或右移 $k$ 位,溢出的位被移除,缺失的位补 $0$,然后异或上左移/右移前的 $a$。 若不可能在 $n$ 次操作内使得 $a=b$,输出 $-1$,否则输出具体操作方案(不用最小化步数)。 **题目描述:** Serval 有两个 $n$ 位二进制整数 $a$ 和 $b$,他想把这两个数字分享给 Toxel。因为 Toxel 更喜欢数字 $b$,所以 Serval 决定通过一些操作(可能为零次)将 $a$ 变为 $b$。在每次操作中,Serval 可以选择任意一个正整数 $k$($1 \leq k \leq n$),并按照以下任一方式改变 $a$: - $a \oplus (a \ll k)$ - $a \oplus (a \gg k)$ 换句话说,这个操作将 $a$ 的每一位左移或右移 $k$ 位,其中溢出的位被移除,缺失的位用 $0$ 填充。将移位结果与原始 $a$ 的按位异或结果赋值给 $a$。 Serval 没有太多时间。他希望最多进行 $n$ 次操作将 $a$ 变为 $b$。请帮助他找出一个操作序列,或者确定无法在最多 $n$ 次操作内将 $a$ 变为 $b$。你不需要最小化操作次数。 在这个问题中,$x \oplus y$ 表示 $x$ 和 $y$ 的[按位异或操作](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)。$a \ll k$ 和 $

加入题单

算法标签: