当前位置:网站首页>A1. Prefix Flip (Easy Version)
A1. Prefix Flip (Easy Version)
2022-08-09 21:55:00 【秦小咩】
A1. Prefix Flip (Easy Version)
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.
=========================================================================
类似问题做过多次,往往就是针对一位置不停改变,使得其余位置不受影响,突破点在于给定的次数,3*n,也就暗示着一个点进行三次变换可以达到只修改着一个点,其余点不会发生改变
XXXXXXXX1把最后一个1变成0而其余不受影响可以按照一下三步
翻转
1XXXXXXXX
翻转1
0XXXXXXXX
打回去
XXXXXXXX1
正好3步
# include<iostream>
# include<string.h>
# include<vector>
using namespace std;
string s,t;
int n;
vector<int>v;
int main ()
{
cin>>n;
while(n--)
{
int len;
cin>>len;
cin>>s>>t;
for(int i=len-1;i>=0;i--)
{
if(s[i]!=t[i])
{
v.push_back(i+1);
}
}
cout<<v.size()*3<<endl;
for(auto it:v)
{
cout<<it<<" "<<1<<" "<<it<<" ";
}
cout<<endl;
v.clear();
}
return 0;
}
边栏推荐
- 简单问题窥见数学
- Blender程序化建模简明教程【PCG】
- 关于ETL的两种架构(ETL架构和ELT架构)
- MLOps的演进历程
- CVPR22 Oral | shunt through multi-scale token polymerization from attention, code is open source
- BulkInsert方法实现批量导入
- 聊天尬死名场面,你遇到过吗?教你一键获取斗图表情包,晋升聊天达人
- Domestic mobile phone manufacturers once fought for it, but now it is the first to collapse...
- Rust 解引用
- 1215 – Cannot add foreign key constraint
猜你喜欢
随机推荐
BulkInsert方法实现批量导入
一本通2074:【21CSPJ普及组】分糖果(candy)
【微服务~Nacos】Nacos之配置中心
金山云地震,震源在字节?
18-GuliMall 压力测试与性能监控
JS解混淆-AST还原案例
一文让你快速了解隐式类型转换【整型提升】!
Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
编译原理之文法
Rust 解引用
OpenMLDB + Jupyter Notebook:快速搭建机器学习应用
This article lets you quickly understand implicit type conversion [integral promotion]!
【软考 系统架构设计师】案例分析⑤ 质量属性和架构评估
Xiaohei's leetcode journey: 94. Inorder traversal of binary trees (supplementary Morris inorder traversal)
PHP 2D array sorted by a field
Shanghai Konan SmartRocket series product introduction (3): SmartRocket iVerifier computer interlocking system verification tool
开发者必备:一文快速熟记【数据库系统】和【软件开发模型】常用知识点
Synchronization lock synchronized traces the source
Simple questions peek into mathematics
Liver all night to write a thirty thousand - word all the commands the SQL database, function, speaks clearly explain operators, content is rich, proposal collection + 3 even high praise!