思路:

字符串其实只有0...0, 0...1, 1...0, 1...1四种。

实现:

 #include <bits/stdc++.h>
using namespace std;
set<string> st[];
bool work(set<string>& a, set<string>& b, map<string, int>& mp, vector<int>& res)
{
int d = a.size() - b.size();
for (auto it: a)
{
if (res.size() == d / ) break;
string tmp = it;
reverse(tmp.begin(), tmp.end());
if (b.count(tmp)) continue;
res.push_back(mp[it]);
}
return res.size() >= d / ;
}
int main()
{
int t; cin >> t;
while (t--)
{
for (int i = ; i < ; i++) st[i].clear();
int n; cin >> n;
map<string, int> mp;
for (int i = ; i < n; i++)
{
string s; cin >> s;
mp[s] = i + ;
int a = *s.begin() - '', b = *(s.end() - ) - '';
int p = a * + b;
st[p].insert(s);
}
if (!st[].empty() && !st[].empty() && st[].empty() && st[].empty())
{
cout << - << endl; continue;
}
vector<int> res;
bool ok = false;
if (st[].size() > st[].size()) ok = work(st[], st[], mp, res);
else ok = work(st[], st[], mp, res);
if (ok)
{
cout << res.size() << endl;
for (auto it: res) cout << it << " ";
cout << endl;
}
else cout << - << endl;
}
return ;
}

CF1277D Let's Play the Words?的更多相关文章

随机推荐

  1. CSS3 新增选择器:伪类选择器和属性选择器

    一.结构(位置)伪类选择器( : ) 1.:first-child 2.:last-child 3.:nth-child(n)或者:nth-child(2n)或者:nth-child(2n+1) &l ...

  2. 洛谷 P1613 跑路 题解

    P1613 跑路 题目描述 小A的工作不仅繁琐,更有苛刻的规定,要求小A每天早上在6:00之前到达公司,否则这个月工资清零.可是小A偏偏又有赖床的坏毛病.于是为了保住自己的工资,小A买了一个十分牛B的 ...

  3. Adobe Acrobat DC

    DC: document cloud [云服务] 但是Adobe document cloud包括: Acrobat DC, Adobe sign, 以及Web和移动应用程序. 参考: https:/ ...

  4. GoCN每日新闻(2019-09-28)

     GoCN每日新闻(2019-09-28) 1. 可视化Go程序的调用图 https://truefurby.github.io/go-callvis/2. Go modules编写和发布官方教程 h ...

  5. 绕流振动UDF【转载】

    宏DEFINE_GRID_MOTION用来移动任意边界和流体区域内的网格节点.它提供了对节点和网格最大限度的操作,可以将刚体运动.变形和相对运动等结合起来.但是使用此UDF时,每一个时间步都必须执行. ...

  6. !!a标签和button按钮只允许点击一次,防止重复提交

    button 方法:加上属性disabled = “disabled” 或者 disabled = “true” <button id="btn" disabled=&quo ...

  7. 雪花ID实现新增数据同步

    雪花ID实现新增数据同步 GUID生成的ID,可以确保是唯一ID,但却是无序的,不适合用于数据同步. 雪花算法生成的ID(INT64)能够按照时间有序(升序)生成.只要电脑上的时间是正确的,新增的记录 ...

  8. vue-router 利用url传递参数

    vue-router 利用url传递参数 :冒号的形式传递参数  在路由配置文件里以:冒号的形式传递参数,这就是对参数的绑定. 1. 在配置文件里以冒号的形式设置参数.我们在/src/router/i ...

  9. python : 设计模式之外观模式(Facade Pattern)

    #为啥要用外观模式举例说明 这个例子很形象,直接从人家博客上贴过来的,参考链接在下面 不知道大家有没有比较过自己泡茶和去茶馆喝茶的区别,如果是自己泡茶需要自行准备茶叶.茶具和开水,如图1(A)所示,而 ...

  10. Android命名规范(重点讲解:包名)

    Android程序开发中,使用规范的命名有益于程序的开发和后期阅读.本文主要对Android程序包名的定义做详细介绍,并附带一些简单的命名规则. 一.标识符命名方法1 .小驼峰命名法,除首单词外,其余 ...