AcWing 3777. 砖块 + 递推
原题链接
简单
作者:
思念是一种病
,
2021-08-20 22:27:26
,
所有人可见
,
阅读 277
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int T,n;
const int N = 210;
string s;
void reverse_(char &c)
{
if(c=='W') c='B';
else c='W';
}
bool check(string s,char c)
{
vector<int> res;
bool flag=false;
for(int i=0;i<n-1;i++)
{
if(s[i]==c) continue;
else
{
reverse_(s[i]);reverse_(s[i+1]);
res.push_back(i);
}
}
if(s.back()==s[0]) flag= true;
if(flag==true)
{
cout << res.size() << endl;
for (auto x: res) cout << x + 1 << ' ';
if (res.size()) cout << endl;
}
return flag;
}
int main()
{
cin>>T;
while(T--)
{
cin>>n;
cin>>s;
if(!check(s,'W') && !check(s,'B')) puts("-1");
}
return 0;
}