https://codeforces.com/problemset/problem/1381/A2
思路:2*n肯定是能一个n次变成一个特殊序列。这样两个串都变成一样的特殊序列就好了。
构造发现总能变成全0或全1.往这个方向去构造。然后B串用一个stack逆序输出就好
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
char str1[maxn],str2[maxn];
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL t;cin>>t;
while(t--){
LL n;cin>>n;
queue<LL>q;
stack<LL>s;
cin>>(str1+1);
cin>>(str2+1);
if(n==1){
if(str1[1]==str2[1]){
cout<<0<<endl;
}
else{
cout<<1<<" "<<1<<endl;
}
continue;
}
LL sum=0;
///A序列全部变成0
for(LL i=1;i<n;i++){
if(str1[i]!=str1[i+1]){
sum++;
if(str1[i]=='1') str1[i]='0';
else if(str1[i]=='0') str1[i]='1';
q.push(i);
}
}
if(str1[n]=='1'){
sum++;
q.push(n);
}
for(LL i=1;i<n;i++){
if(str2[i]!=str2[i+1]){
sum++;
if(str2[i]=='1') str2[i]='0';
else if(str2[i]=='0') str2[i]='1';
s.push(i);
}
}
if(str2[n]=='1'){
sum++;
s.push(n);
}
cout<<sum<<" ";
while(!q.empty()){
cout<<q.front()<<" ";
q.pop();
}
while(!s.empty()){
cout<<s.top()<<" ";
s.pop();
}
cout<<endl;
}
return 0;
}