当前位置:网站首页>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;
}
边栏推荐
- The kvm virtual machine cannot be started, NOT available, and the PV is larger than the partition
- Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
- TF uses constant to generate data
- 用户代码未处理MetadataException
- navicat 快捷键
- UML类图五种关系的代码实现[通俗易懂]
- String hashing (2014 SERC J question)
- random.normal() and random.truncated_normal() in TF
- Arcgis工具箱无法使用,显示“XML包含错误“的解决方法
- 为什么这么多人都想当产品经理?
猜你喜欢
【微服务~Nacos】Nacos之配置中心
One Pass 2074: [21CSPJ Popularization Group] Candy
Domestic mobile phone manufacturers once fought for it, but now it is the first to collapse...
Bean life cycle
Reinforcement Learning Weekly Issue 57: DL-DRL, FedDRL & Deep VULMAN
Flask入门学习教程
Several ways to draw timeline diagrams
《强化学习周刊》第57期:DL-DRL、FedDRL & Deep VULMAN
MLOps的演进历程
Pagoda measurement - building LightPicture open source map bed system
随机推荐
xctf攻防世界 Web高手进阶区 shrine
TRUNCATE表之后空间未释放
Flask入门学习教程
Xiaohei's leetcode journey: 94. Inorder traversal of binary trees (supplementary Morris inorder traversal)
STC8H development (15): GPIO drive Ci24R1 wireless module
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
为什么这么多人都想当产品经理?
PHP 2D array sorted by a field
【GORM】模型关系-HasMany关系
Basic operations of openGauss database (super detailed)
聊天尬死名场面,你遇到过吗?教你一键获取斗图表情包,晋升聊天达人
Rust 解引用
你的 Link Button 能让用户选择新页面打开吗?
反射机制篇
Common commands and technical function modules of Metasploit
SecureCRT background color
Arcgis工具箱无法使用,显示“XML包含错误“的解决方法
The round functions in the np, ceil function and floor function
POWER SOURCE ETA ETA Power Repair FHG24SX-U Overview
js数组对象去重