这题真的…想通了是个智障题,没想通思路巨尼玛复杂
关键来了,00和11是很特殊的,他们对当前局面不会有任何影响
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int t,n,l[maxn];
string s[maxn];
map<string,int>mp;
vector<int>vec;
int main()
{
cin >> t;
while( t-- )
{
mp.clear(); vec.clear();
cin >> n;
int zero=0,one=0,two=0,three=0;
for(int i=1;i<=n;i++)
{
cin >> s[i];
l[i]=s[i].length()-1;
if( s[i][0]=='0'&&s[i][l[i]]=='0' ) zero++;
else if( s[i][0]=='0'&&s[i][l[i]]=='1' ) one++;
else if( s[i][0]=='1'&&s[i][l[i]]=='0' ) two++;
else three++;
string w=s[i];
reverse(w.begin(),w.end() );
mp[w]=1;//翻转后存在vector
}
for(int i=1;i<=n;i++)
{
if( s[i][0]=='0'&&s[i][ l[i] ]=='1'&&!mp[ s[i] ] )
{
if( one-two>1 ) vec.push_back(i),one--,two++;
}
if( s[i][0]=='1'&&s[i][ l[i] ]=='0'&&!mp[ s[i] ])
{
if( two-one>1 ) vec.push_back(i),two--,one++;
}
}
if( !one&&!two&&zero&&three )
cout << -1 << endl;
else
{
int len=vec.size();
cout << len << endl;
for(int i=0;i<len;i++) cout << vec[i] << " ";
cout << endl;
}
}
}