A1. Prefix Flip (Easy Version)

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

This is the easy version of the problem. The difference between the versions is the constraint on nn and the required number of operations. You can make hacks only if all versions of the problem are solved.

There are two binary strings aa and bb of length nn (a binary string is a string consisting of symbols 00 and 11). In an operation, you select a prefix of aa, and simultaneously invert the bits in the prefix (00 changes to 11 and 11 changes to 00) and reverse the order of the bits in the prefix.

For example, if a=001011a=001011 and you select the prefix of length 33, it becomes 011011011011. Then if you select the entire string, it becomes 001001001001.

Your task is to transform the string aa into bb in at most 3n3n operations. It can be proved that it is always possible.

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000)  — the number of test cases. Next 3t3t lines contain descriptions of test cases.

The first line of each test case contains a single integer nn (1≤n≤10001≤n≤1000)  — the length of the binary strings.

The next two lines contain two binary strings aa and bb of length nn.

It is guaranteed that the sum of nn across all test cases does not exceed 10001000.

Output

For each test case, output an integer kk (0≤k≤3n0≤k≤3n), followed by kk integers p1,…,pkp1,…,pk (1≤pi≤n1≤pi≤n). Here kk is the number of operations you use and pipi is the length of the prefix you flip in the ii-th operation.

Example

input

Copy

5
2
01
10
5
01011
11100
2
01
01
10
0110011011
1000110100
1
0
1

output

Copy

3 1 2 1
6 5 2 5 3 1 2
0
9 4 1 2 10 4 1 2 1 5
1 1

Note

In the first test case, we have 01→11→00→1001→11→00→10.

In the second test case, we have 01011→00101→11101→01000→10100→00100→1110001011→00101→11101→01000→10100→00100→11100.

In the third test case, the strings are already the same. Another solution is to flip the prefix of length 22, which will leave aa unchanged.

解题说明:此题是简单版本,通过观察容易发现执行操作i后第i个元素跑到第1个位置,于是就可以想到一种构造方法:
到a与b的第i个元素不同
执行操作i(取反并翻转前i个元素)
执行操作1(取反并翻转第1个元素)
执行操作i(取反并翻转前i个元素)
可以发现第i个元素取反了3次,前i - 1个元素取反了2次,并且前i个元素均翻转了两次,相比操作前,之后第i个元素发生了变化,并且很容易看出操作数不超过3n,因为每个元素不同,至多执行3次操作。

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	while (t--) 
	{
		int n;
		cin >> n;
		string a, b;
		cin >> a >> b;
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			if (a[i] != b[i])
			{
				ans++;
			}
		}
		cout << 3 * ans << " ";
		for (int i = 0; i < n; i++)
		{
			if (a[i] != b[i])
			{
				cout << i + 1 << " 1 " << i + 1 << " ";
			}
		}
		cout << "\n";
	}
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值